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.

采纳的回答

Walter Roberson
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 个)

类别

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