How to extract indices with a condition?

79 visualizaciones (últimos 30 días)
Mr M.
Mr M. el 26 de Mzo. de 2018
Comentada: Walter Roberson el 29 de Feb. de 2024
For example I have Y = X(X==42), but I need the indices also!
  2 comentarios
Stephen23
Stephen23 el 26 de Mzo. de 2018
X==42 gives the logical indices, which will be faster than using find.
rbih rbih
rbih rbih el 12 de Jun. de 2020
hi Mr M. i just wondering about the value that you're searching index for (42), isn't that related to the quiz of rigid body kinematics course (Concept Check 9 - Euler Angle Differential Kinematic Equations) on coursera!
just for fun, have a good day.

Iniciar sesión para comentar.

Respuesta aceptada

Birdman
Birdman el 26 de Mzo. de 2018
Editada: Birdman el 26 de Mzo. de 2018
To find the index where X is equal to 42, type
idx=find(X==42)
Y=X(idx)

Más respuestas (1)

Walter Roberson
Walter Roberson el 26 de Mzo. de 2018
find(X==42) and store in a variable. Then X(that_variable)
  10 comentarios
Ron
Ron el 29 de Feb. de 2024
@Rik, thanks for replying. Yes my comment was somewhat arbitrary here. Yes I was talking about "X(setdiff(1:numels(X), ind0))", this statement. I couldnt understand what it means. Yes you are right about the typo, thanks for correcting me.
Walter Roberson
Walter Roberson el 29 de Feb. de 2024
setdiff(1:numels(X), ind0)
returns all the indices of X that do not appear in ind0
It is questionable whether this will be any faster than
X(X ~= 0)
but the original poster wanted a different way.

Iniciar sesión para comentar.

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by