Confusion on Meshgrid and interp2

6 visualizzazioni (ultimi 30 giorni)
Michael Lynch
Michael Lynch il 2 Giu 2020
Commentato: darova il 14 Giu 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 Commento
darova
darova il 14 Giu 2020
You code is correct. Just add these lines
scatter3(m(:),n(:),f(:))
surface(x,y,z)

Accedi per commentare.

Risposte (1)

David Hill
David Hill il 2 Giu 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 Commento
Michael Lynch
Michael Lynch il 2 Giu 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

Accedi per commentare.

Prodotti


Release

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by