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]

5 views (last 30 days)
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]

Accepted Answer

dpb
dpb on 8 May 2014
B=A(A(:,1)==1,:);
Lookup "logical addressing" in documentation for details on how this works--it's important Matlab syntax.
  6 Comments
dpb
dpb on 10 May 2014
Edited: dpb on 10 May 2014
That's really tilting at windmills if were to let this level of mis- or incomplete specification stop us in our tracks! (vbg)

Sign in to comment.

More Answers (1)

Image Analyst
Image Analyst on 10 May 2014
You say "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]" You just gave the answer in the question itself! The answer is
B=[1 2 3; 1 2 9];
Read your question. The matrix A is not involved AT ALL in how you came up with B. No criteria or tests were to be applied to A, so A can just be ignored.

Categories

Find more on Resizing and Reshaping Matrices in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!