1

I'm new to matlab and would like to create a new vector equal to a row of an nxn matrix that I already have. I know how to do it with loops but is there a command? Something like

vector1=matrix1(row5)

Thanks!

user1707675
  • 21
  • 1
  • 2
  • 9
  • 5
    `Vector = Matrix(RowNumber, :);` -This is really basic Matlab. If you are a brand new user, might I suggest working through one of the beginner tutorials [here](http://www.mathworks.com.au/academia/student_center/tutorials/launchpad.html) before asking any further questions on SO. I'm not trying to put you off asking questions here, just pointing out that the solution to this question will be in the first couple of pages of any beginner tutorial on Matlab. – Colin T Bowers Aug 28 '13 at 02:21
  • @ColinTBowers U can make it an anwser for upvotes:-) – Marcin Aug 28 '13 at 02:32
  • @Marcin To be honest, I'm content for a newer user to get the up-votes for a question like this. I've always felt a few easy answers helps get them started, and then hopefully they'll continue to contribute. – Colin T Bowers Aug 28 '13 at 10:24
  • related question: [How to select a submatrix (not in any particular pattern) in Matlab](http://stackoverflow.com/q/13091193/1336150). Also related: [this](http://www.mathworks.com/help/matlab/math/matrix-indexing.html) and [this](http://www.mathworks.com/company/newsletters/articles/matrix-indexing-in-matlab.html)... – Eitan T Aug 28 '13 at 11:35

1 Answers1

2

Yep this is easy, the syntax is:

row5Vector = matrix1(5,:);

Also to grab a column you could:

col5Vector = matrix1(:,5);

PeterM
  • 2,372
  • 1
  • 26
  • 35