I have 2D array of size 16*16 stored in a variable temp and I have set of x and y values x=[1 2 3]; y=[4 5 6]; I want to extract values from temp variable indexed by (x,y)=(1,4) (2,5) (3,6) without using for loop. Thank you.
1 回表示 (過去 30 日間)
古いコメントを表示
I have 2D array of size 16*16 stored in a variable temp and I have set of x and y values x=[1 2 3]; y=[4 5 6]; I want to extract values from temp variable indexed by (x,y)=(1,4) (2,5) (3,6) without using for loop. Thank you.
0 件のコメント
採用された回答
Walter Roberson
2015 年 12 月 30 日
values = YourMatrix( sub2ind(size(YourMatrix), x, y) );
The faster form of this for a 16 x 16 matrix is
YourMatrix(x + (y-1)*16)
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Matrices and Arrays についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!