Indexing any true in logical vector
Show older comments
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
Accepted Answer
More Answers (0)
Categories
Find more on Matrices and Arrays in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!