How to extract indices with a condition?
Afficher commentaires plus anciens
For example I have Y = X(X==42), but I need the indices also!
2 commentaires
Stephen23
le 26 Mar 2018
X==42 gives the logical indices, which will be faster than using find.
rbih rbih
le 12 Juin 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.
Réponse acceptée
Plus de réponses (1)
Walter Roberson
le 26 Mar 2018
1 vote
find(X==42) and store in a variable. Then X(that_variable)
10 commentaires
Birdman
le 26 Mar 2018
For nonzero indices, simply type
find(X~=0)
Mr M.
le 26 Mar 2018
Mr M.
le 26 Mar 2018
Birdman
le 26 Mar 2018
It is possible to do faster, yes, by using logical indexing.
Walter Roberson
le 26 Mar 2018
X(setdiff(1:numels(X), ind0))
Ron
le 23 Fév 2024
can you please this statement? thankyou.
Walter Roberson
le 29 Fév 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.
Catégories
En savoir plus sur Performance and Memory dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!