1
votes

In matlab, I have a matrix and index vector v (in real problem, v vector is very long)

A = [1,2,3;4,5,6;7,8,9]; % 3-by-3 matrix
v = [1,2,3,2,3,3,1]

How can I generate a matrix like

[A(1,:);A(2,:);A(3,:);A(2,:);A(3,:);A(3,:);A(1,:)]

without using loop or write out everything explicitly?

1

1 Answers

7
votes

You can use vectors to index, A([1,1,1]) would give you three times the first element.

A(v,:)