How to find rows in a matrix that have elements in a certain column that satisfy certain condition and create a new matrix out of those rows?

1 view (last 30 days)
I might not have phrased the question best, but I got a matrix that has 5 columns and thousands of rows, and now I want to find rows that have elements in 5th column that satisfy certain condition(equal to 0 or 2 or 10) and create new matrix with those exact rows?
Thanks in advance.

Accepted Answer

Walter Roberson
Walter Roberson on 30 Aug 2015
tf = ismember(YourMatrix(:,5), [0, 2, 10]);
NewMatrix = YourMatrix(tf, :);

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!