index array to access the value in matrix
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
Shubham Gupta
2019-11-14
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.
采纳的回答
Shubham Gupta
2019-11-14
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
更多回答(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!