MATLAB: NAN from griddata for scatteredInterpolant

griddataMATLABscatteredinterpolant

Hello,
I have a set of data (x,y,v) that i got from CFD analesys.
x and y vector not unique or sort in any way, but there are not single (x,y) that repet.
i want to interpolate my data to get lower resolution but i cant get it to work
F = scatteredInterpolant(x_c,y_c,z_c);
xi=linspace(min(min(x_c)),max(max(x_c)),100);
yi=linspace(min(min(y_c)),max(max(y_c)),100);
zi=F(xi,yi);
[XI, YI] = meshgrid(sort(xi), sort(xi));
ZI = griddata(xi, yi, zi, XI, YI);
ZI just return NAN

Best Answer

Your problem is that you have no idea how to use those tools. There is no need to use griddata AFTER you used scatteredInterpolant! Here is your data.
untitled.jpg
Scattered data, with some nasty stuff to interpolate on the edges, but still what appears to be a single valued relationship. There will be some areas where you get garbage.
F = scatteredInterpolant(x_c,y_c,z_c);
xi=linspace(min(min(x_c)),max(max(x_c)),100);
yi=linspace(min(min(y_c)),max(max(y_c)),100);
[Xg,Yg] = meshgrid(xi,yi);
Zg = F(Xg,Yg);
surf(Xg,Yg,Zg)
xlabel X
ylabel Y
zlabel Z
grid on
box on
hold on
plot3(x_c,y_c,z_c,'r.')
untitled.jpg
As you see, it follows the data, and does so reasonably well. In some places, around the edges, if you look carefully at the plot, you will see what I would call interpolation artifacts, what I called garbage before. They are more difficult to eliminate.
Related Question