Effacer les filtres
Effacer les filtres

reverse indexing with conditions

9 vues (au cours des 30 derniers jours)
cgo
cgo le 9 Nov 2015
Commenté : cgo le 9 Nov 2015
Let A = [1 2 4 6 10], I want to find the indices of the matrix for which the element less than 5.
So if I say: A < 5, then it will return [1 1 1 0 0]. How can I proceed to get the index of all those 1's?
Thanks

Réponse acceptée

TastyPastry
TastyPastry le 9 Nov 2015
idx = 1:numel(A);
mask = A < 5;
idx = idx(mask);
  1 commentaire
cgo
cgo le 9 Nov 2015
thanks

Connectez-vous pour commenter.

Plus de réponses (1)

Thorsten
Thorsten le 9 Nov 2015
Modifié(e) : Thorsten le 9 Nov 2015
To get numerical indices, use find
idx = find(A < 5);
You can also use logical indices, that are often faster:
idx = A < 5;
In both cases you get the indexed numbers using
A(idx)
  1 commentaire
cgo
cgo le 9 Nov 2015
perfect. thanks

Connectez-vous pour commenter.

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by