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)
Show older comments
Bogdan Pavlovic
on 30 Aug 2015
Commented: Bogdan Pavlovic
on 30 Aug 2015
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.
0 Comments
Accepted Answer
Walter Roberson
on 30 Aug 2015
tf = ismember(YourMatrix(:,5), [0, 2, 10]);
NewMatrix = YourMatrix(tf, :);
More Answers (0)
See Also
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!