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 个)

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 CenterFile Exchange 中查找有关 Surface 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