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 view (last 30 days)
Show older comments
varun rao
on 30 Dec 2015
Answered: Walter Roberson
on 30 Dec 2015
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 Comments
Accepted Answer
Walter Roberson
on 30 Dec 2015
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 Comments
More Answers (0)
See Also
Categories
Find more on Matrices and Arrays in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!