フィルターのクリア

Confusion on Meshgrid and interp2

2 ビュー (過去 30 日間)
Michael Lynch
Michael Lynch 2020 年 6 月 2 日
コメント済み: darova 2020 年 6 月 14 日
So i have x and y coordinates and i need to create sample points for the x and y coordinates to be evaluated at. I must use interp2 on these points in order to graph them.
I thought it would look something like this.
x = -0.5:0.1:0.5;
y = -0.5:0.1:0.5;
k = 0.77;
[x,y] = meshgrid(x,y);
z = k*(x.^2-y.^2);
m = [-0.5 0 0.5];
n = [-0.5 -0.25 0.25 0.5];
[m,n] = meshgrid(m,n);
f = interp2(x,y,z,m,n);
surf(x,y,f)
I am confused on where to go from here any help would be greatly appreciated.
  1 件のコメント
darova
darova 2020 年 6 月 14 日
You code is correct. Just add these lines
scatter3(m(:),n(:),f(:))
surface(x,y,z)

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

回答 (1 件)

David Hill
David Hill 2020 年 6 月 2 日
x = -0.5:0.1:0.5;
y = -0.5:0.1:0.5;
k = 0.77;
[x,y] = meshgrid(x,y);
z = k*(x.^2-y.^2);
m = [-0.5 0 0.5];
n = [-0.5 -0.25 0.25 0.5];
[m,n] = meshgrid(m,n);
f = interp2(x,y,z,m,n);%you are interpolating m and n to the x and y values; therefore f is the size of [m,n]
surf(m,n,f);%have to plot f against m and n (same size)
  1 件のコメント
Michael Lynch
Michael Lynch 2020 年 6 月 2 日
I don't think this quite what i was looking for. Do you know how I can plot the surf with the meshgrid of x and y? I only want m and n to be the query points I think

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

カテゴリ

Help Center および File ExchangeSurface and Mesh Plots についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by