# Problem with Interpolation function involving 2 variables

2 views (last 30 days)
Sangani Prithvi on 2 Sep 2021
Commented: Walter Roberson on 2 Sep 2021
Hi,
I've tried to use the interp2 function to interpolate 'Zq' coordinates from the raw 'X,Y,Z' data attached in the file here. Interpolation is carried for Xq = -60:60 and Yq = -160:160.
I'm getting an error of this kind when I run the program.
" Error using griddedInterpolant
The grid vectors must be strictly monotonically increasing"
Is there a way to find the interpolation for such data?
KSSV on 2 Sep 2021
Use meshgrid for Xq and Yq.

Walter Roberson on 2 Sep 2021
F = scatteredInterpolant(T.X, T.Y, T.Z);
Xq = -60:60;
Yq = -160:160;
[XQ, YQ] = meshgrid(Xq, Yq);
ZQ = F(XQ, YQ);
surf(XQ, YQ, ZQ, 'edgecolor', 'none');
xlabel('x'); ylabel('y'); zlabel('z')
Sangani Prithvi on 2 Sep 2021
Thank you very much.

### More Answers (1)

KSSV on 2 Sep 2021
T = readtable('xyz.xlsx') ;
x = T.X ; y = T.Y ; z = T.Z;
Xq = -60:60 ;
Yq = -160:160. ;
[Xq,Yq] = meshgrid(Xq,Yq) ;
Zq = griddata(x,y,z,Xq,Yq) ;
##### 3 CommentsShow 1 older commentHide 1 older comment
KSSV on 2 Sep 2021
You will get only where the points lie outside the give data.
Walter Roberson on 2 Sep 2021
You might want to set an extrapolation method.