Using Nx1 vector as index to extract values from an NxM matrix and create an Nx1 vector
Afficher commentaires plus anciens
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!
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Creating and Concatenating Matrices dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!