MATLAB: How to extract indices with a condition

boolconditionindicesvector

For example I have Y = X(X==42), but I need the indices also!

Best Answer

To find the index where X is equal to 42, type
idx=find(X==42)
Y=X(idx)