Indexing (extracting value from rows)

1 回表示 (過去 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)
  1 件のコメント
dan berkowitz
dan berkowitz 2019 年 6 月 8 日
Thank you!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMultidimensional Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by