Indexing (extracting value from rows)

조회 수: 2 (최근 30일)
dan berkowitz
dan berkowitz 2019년 6월 5일
댓글: dan berkowitz 2019년 6월 8일
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

채택된 답변

Matt J
Matt J 2019년 6월 5일
idx=sub2ind(size(A), ones(size(B)), B);
A(idx)

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by