index array to access the value in matrix
1 view (last 30 days)
Show older comments
Hi all, I have 3 matrixes as matrix IM (200x200); X(400x400); Y(400x400). As matrix x and y is indexing the matrix IM. How can I use x and y matrix to access the value of matrix IM withouf for loop.
2 Comments
Shubham Gupta
on 14 Nov 2019
Can you please share mat file or put a small example to show what is stored in X,Y & IM?
Small example can be like X&Y of size 4x4 & IM being 2x2, then you can show desired output for this example.
Accepted Answer
Shubham Gupta
on 14 Nov 2019
Step1 - Convert the subscript to indeces using x & y(Hint: sub2ind)
Step2 - Calculate values of IM for calculated indeces
Step3 - Reshape it to match the dimesion with x or y (Hint: reshape)
Something like this:
output = reshape(IM(sub2ind(size(IM),x(:),y(:))),size(x,1),size(x,2));
Let me know if you have doubt
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!