Ozge
Ozge

Reputation: 11

Copying Two or More Rows from one matrix to another

I am trying to reach and store 4 rows from a square matrix. Can you please help me? I have square matrix with size 10 x 10 and I am looking for rows number 2, 5, 6 and 9 to store them in one matrix.

Upvotes: 1

Views: 84

Answers (2)

Tim Biegeleisen
Tim Biegeleisen

Reputation: 522732

You can select the submatrix you want using this code:

B = A([2 5 6 9], :)

The : subscript will select all columns, which I am assuming is what you want.

Upvotes: 3

Sнаđошƒаӽ
Sнаđошƒаӽ

Reputation: 17612

Learned from here and seems fairly easy. Try this

x = randi(10, 10);
x
y = x([2 5 6 9], :);
y

y then contains the rows 2, 5, 6, 9 from x. Hope that helps.

Upvotes: 1

Related Questions