MATLAB: Is there any more effiecient way to implement this

interpolationscatteredinterpolant

Using MATLAB:I have a table of lets say x(size(100×1)),y(size(100×1)) and z(size(100×100)) and i use
z1 = interp2(x,y,z,x1,x2)
to find a scalar value that i need for later calculation. I was wondering if there is a more efficient/quicker way to implement this.scatteredInterpolant function could help? I tried unsuccessfully to implement it with scatteredInterpolant

Best Answer

scatteredInterpolant is suitable for cases where your source grid is scattered. If you were able to use interp2 it means that your source grid is not scattered. Although you can still use scattered interpolant, it does not give you any additional benefit.
Here are two approaches:
1) using gridded interpolant:
[XGrid,YGrid]=meshgrid(x,y);
F=griddedInterpolant(XGrid',YGrid',z','cubic');
Then you can query that for any point as follow:
z1=F(x1,x2);
x1,x2 could be scattered points or gridded. If it is gridded it should follow NDGrid format.
2) Using Scattered Interpolant:
[XGrid,YGrid]=meshgrid(x,y);
F=scatteredInterpolant(XGrid(:), YGrid(:),z(:));
Then you can query that for any point as follow:
z1=F(x1,x2);