Indexing (extracting value from rows)

1 vue (au cours des 30 derniers jours)
dan berkowitz
dan berkowitz le 5 Juin 2019
Commenté : dan berkowitz le 8 Juin 2019
Hi,
I have a 5 x 5 array, A, and a 5 x 1 array, B = [2 3 1 4 3]'. How can I extract the element from each row of A as they occur in B. i.e., I want the 2nd value of row one of A, they 3rd value of row two of A, ..., and the 3rd value of row five of A.
Any help would be appreciated.
db

Réponse acceptée

Matt J
Matt J le 5 Juin 2019
idx=sub2ind(size(A), ones(size(B)), B);
A(idx)

Plus de réponses (0)

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by