1
votes

Consider an n-by-k matrix M and an p-by-1 vector of indexes V ranging from 1 to n. How can I create the p-by-k matrix C where each row corresponds to the entry of M referred to by the value in each row of V.

Example

M = 1 1
    1 2
    1 3
    1 4

and

V = 2
    1
    3

What I require is the matrix

C = 1 2
    1 1
    1 3
1
What does "refereed" mean in this case? Can you provide a small numerical example? Your language and description is rather too exotic for me.rayryeng
@rayryeng I believe it means "referred".beaker
This is basic matrix indexing. See mathworks.com/help/matlab/math/matrix-indexing.html#f1-85553, specifically the second example in this section.beaker

1 Answers

1
votes

To assign the rows V of matrix M to a matrix C, you would write:

C = M(V,:);