Using Nx1 vector as index to extract values from an NxM matrix and create an Nx1 vector
Show older comments
Hi. I will try to explain my title:
I have an NxM matrix, e. g.
M = [1 2 3; 4 5 6; 7 8 9];
and an Nx1 index vector, e. g.
I = [2; 3; 1];
I would like to create a vector V using I as an index for M to extract values from M so that
V(i) = M(i,I(i))
without using a loop, if possible.
So the resulting vector V in this example would result as:
V = [2; 6; 7];
Thanks for any help or hints!
Accepted Answer
More Answers (0)
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!