MATLAB: New matrix from all based on some criteria

keep observationsmake smaller matrix

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!

Best Answer

B = A(A(:,2) == 2,:)