Extract data from matrices and arrays using vectors of coordinates
71 ビュー (過去 30 日間)
古いコメントを表示
Ariel Kessel Akerman
2021 年 9 月 28 日
コメント済み: Ariel Kessel Akerman
2021 年 9 月 28 日
I have a matrix and I want to use two vectors of row and column index coordinates in order to extract the elements from it. In particular, I can define a 3 x 3 matrix as
A = [1 2 3; 3 4 5; 8 9 10]
And I want to use two vectors to extract the elements (2,2), (3,1), (1,3). My intention is to do this using the vectors for each corrdinates. I have been trying to do it by writing
A([2 3 1], [2 1 3])
but of course this is not working. I believe that this is a basic sintax issue.
Thank you so much
0 件のコメント
採用された回答
the cyclist
2021 年 9 月 28 日
編集済み: the cyclist
2021 年 9 月 28 日
Using your example:
A = [1 2 3; 3 4 5; 8 9 10]
linearIndex = sub2ind(size(A),[2 3 1], [2 1 3])
A(linearIndex)
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!