index array to access the value in matrix

조회 수: 1 (최근 30일)
AniCnx
AniCnx 2019년 11월 14일
댓글: AniCnx 2019년 11월 15일
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
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.
AniCnx
AniCnx 2019년 11월 14일
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

댓글을 달려면 로그인하십시오.

채택된 답변

Shubham Gupta
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
  댓글 수: 1
AniCnx
AniCnx 2019년 11월 15일
Thank you very much. it works very well.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by