New matrix from all based on some criteria

4 views (last 30 days)
Hi,
Probably this is a very simple question, but I am new to Matlab and can't find the answer so would appriciate your help.
For example, I have a matrix: A= [1, 2, 4; 2 , 3, 1; 2, 3, 5; 1 , 2, 1];
How can I create another matrix based on criteria that, for example, value in second column is 2? What I want to get is:
B=[1,2,4; 1, 2,1];
Thanks!

Accepted Answer

Andrei Bobrov
Andrei Bobrov on 23 Mar 2012
B = A(A(:,2) == 2,:)

More Answers (0)

Categories

Find more on Creating and Concatenating Matrices 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!