MATLAB: I have a matrix A=[1 2 3; 1 2 9; 2 3 4]. I want a matrix B whose column 1 is equal to 1. How to do this? B=[1 2 3; 1 2 9]

matrix

I have a matrix A=[1 2 3; 1 2 9; 2 3 4]. I want a matrix B whose column 1 is equal to 1. How can I do this? B=[1 2 3; 1 2 9]

Best Answer

B=A(A(:,1)==1,:);
Lookup "logical addressing" in documentation for details on how this works--it's important Matlab syntax.