Filter löschen
Filter löschen

Confusion on Meshgrid and interp2

2 Ansichten (letzte 30 Tage)
Michael Lynch
Michael Lynch am 2 Jun. 2020
Kommentiert: darova am 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 Kommentar
darova
darova am 14 Jun. 2020
You code is correct. Just add these lines
scatter3(m(:),n(:),f(:))
surface(x,y,z)

Melden Sie sich an, um zu kommentieren.

Antworten (1)

David Hill
David Hill am 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 Kommentar
Michael Lynch
Michael Lynch am 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

Melden Sie sich an, um zu kommentieren.

Produkte


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by