Moving from an index in the matrix to an x,y value

5 ビュー (過去 30 日間)
Yovel
Yovel 2024 年 1 月 19 日
回答済み: Star Strider 2024 年 1 月 19 日
Hey
I have a 50x50 matrix that indicates points on the X,Y axis
I have some kind of function that holds the index that indicates a row and a column of some point.
My question is how do I go from an index to get the real value on the X axis and Y axis?
Let's say the indexes I got are:
row_idx=43, col_idx=3
Can I say that the value of the point is (3,7)? Or should we add 1+ to the y value? I got confused..
Thank you
  1 件のコメント
the cyclist
the cyclist 2024 年 1 月 19 日
I got confused, too.
Maybe you could post a much smaller example (say, 5x5) of your matrix. Then, what is your input, and what should the output be?

サインインしてコメントする。

回答 (1 件)

Star Strider
Star Strider 2024 年 1 月 19 日
Perhaps something like this —
x = linspace(0, 10, 50);
y = linspace(0, 10, 50);
zm = exp(-(x-4.5).^2/4) .* exp(-(y(:)-4.5).^2/4);
[xm,ym] = ndgrid(x,y);
Zfcn = scatteredInterpolant(xm(:),ym(:),zm(:));
row_idx = 43;
col_idx = 3;
xq = interp1(x, row_idx)
xq = 8.5714
yq = interp1(y, col_idx)
yq = 0.4082
zi = Zfcn(xq,yq);
figure
surf(xm, ym, zm)
hold on
plot3(xq, yq, zi, 'rp', 'MarkerFaceColor','r', 'MarkerSize',15)
hold off
grid on
xlabel('x')
ylabel('y')
zlabel('z')
[az,el] = view
az = -37.5000
el = 30
% view(210,el)
.

カテゴリ

Help Center および File ExchangeMathematics についてさらに検索

タグ

製品


リリース

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by