Indexing any true in logical vector
Afficher commentaires plus anciens
Is there an easy way of reducing the true values in logical vector so as only one true would remain?
Example:
A = [1 2 3 4 5 6];
v = [1 0 1 0 1 0];
Now I need to pick either 1, 3 or 5 from A, I don't care wich one. Insted of using find:
ind_v = find(v);
Result = A(ind_v(1));
I'd like to do it more elegant, like
Result = A(FirstTrue(v));
Is there a way or should I stick with find? THX
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Matrices and Arrays 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!