clear all
close all
n = 20;
x = -cos(linspace(0,pi,n));
y = 2*sin(linspace(-pi/2,pi/2,2*n));
% not equispaced meshgridded X and Y
[X,Y] = meshgrid(x,y);
Z = sin(X).*cos(Y);
XI = linspace(-1,1,2*n);
YI = linspace(-2,2,3*n)';
% ZI corresponds to meshgrid(XI,YI)
ZI = newinterp2(X,Y,Z,XI,YI);
mesh(XI,YI,ZI)
xlabel('x')
ylabel('y')
[XI,YI] = meshgrid(XI,YI);
norm(ZI(:)-sin(XI(:)).*cos(YI(:)),Inf)
XI = 2*rand(2,10*n)-1;
YI = 4*rand(2,10*n)-2;
% scattered
ZI = newinterp2(X,Y,Z,XI,YI);
figure
plot3(XI(:),YI(:),ZI(:),'*')
xlabel('x')
ylabel('y')
norm(ZI(:)-sin(XI(:)).*cos(YI(:)),Inf)