Reputation: 57
I have a matrix
X = [1 1;2 2;3 3;4 4];
Y = [2 4];
I want a resulting matrix z
to have just rows 2 and 4 (the values in Y
) of X
. That is,
Z = [2 2;4 4];
Any solutions?
Upvotes: 0
Views: 2659
Reputation: 17656
Z = X(Y,:);
This is a pretty easily researched question in my opinion: the first result for "MATLAB matrix indexing" answers your question and has a lot more general information about selecting parts of MATLAB matrices.
Upvotes: 8