Confusion on Meshgrid and interp2

6 views (last 30 days)
Michael Lynch
Michael Lynch on 2 Jun 2020
Commented: darova on 14 Jun 2020
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 Comment
darova
darova on 14 Jun 2020
You code is correct. Just add these lines
scatter3(m(:),n(:),f(:))
surface(x,y,z)

Sign in to comment.

Answers (1)

David Hill
David Hill on 2 Jun 2020
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 Comment
Michael Lynch
Michael Lynch on 2 Jun 2020
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

Sign in to comment.

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!