index array to access the value in matrix

1 vue (au cours des 30 derniers jours)
AniCnx
AniCnx le 14 Nov 2019
Commenté : AniCnx le 15 Nov 2019
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 commentaires
Shubham Gupta
Shubham Gupta le 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.
AniCnx
AniCnx le 14 Nov 2019
IM=4.08809852121212 4.29250344727273 4.39470591030303 4.44580714181818 4.44580714181818 4.54800960484849 4.65021206787879 4.75241453090909 4.80351576242424 4.95681945696970
4.39470591030303 4.44580714181818 4.49690837333333 4.54800960484849 4.59911083636364 4.65021206787879 4.75241453090909 4.80351576242424 4.85461699393939 4.95681945696970
4.34360467878788 4.44580714181818 4.49690837333333 4.59911083636364 4.59911083636364 4.65021206787879 4.75241453090909 4.80351576242424 4.80351576242424 4.90571822545455
4.34360467878788 4.39470591030303 4.49690837333333 4.59911083636364 4.59911083636364 4.70131329939394 4.75241453090909 4.75241453090909 4.75241453090909 4.85461699393939
4.29250344727273 4.39470591030303 4.44580714181818 4.54800960484849 4.59911083636364 4.70131329939394 4.70131329939394 4.75241453090909 4.80351576242424 4.80351576242424
4.29250344727273 4.34360467878788 4.44580714181818 4.54800960484849 4.59911083636364 4.70131329939394 4.75241453090909 4.75241453090909 4.80351576242424 4.80351576242424
4.29250344727273 4.34360467878788 4.39470591030303 4.49690837333333 4.59911083636364 4.70131329939394 4.75241453090909 4.80351576242424 4.80351576242424 4.80351576242424
4.29250344727273 4.34360467878788 4.39470591030303 4.49690837333333 4.59911083636364 4.75241453090909 4.75241453090909 4.75241453090909 4.80351576242424 4.80351576242424
4.34360467878788 4.34360467878788 4.39470591030303 4.49690837333333 4.59911083636364 4.70131329939394 4.80351576242424 4.80351576242424 4.80351576242424 4.85461699393939
4.44580714181818 4.44580714181818 4.39470591030303 4.49690837333333 4.59911083636364 4.70131329939394 4.75241453090909 4.75241453090909 4.80351576242424 4.80351576242424
x=1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3
3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3
4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5
5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5
6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7
7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7
8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8
8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8
9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9
9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9
10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10
10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10
y=1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10
1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10
1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10
1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10
1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10
1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10
1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10
1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10
1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10
1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10
1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10
1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10
1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10
1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10
1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10
1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10
1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10
1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10
1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10
1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10

Connectez-vous pour commenter.

Réponse acceptée

Shubham Gupta
Shubham Gupta le 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
  1 commentaire
AniCnx
AniCnx le 15 Nov 2019
Thank you very much. it works very well.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Matrices and Arrays dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by