matlab Error: Input grid is an invalid Meshgrid

Viewed 716

I want to interpolate an irregular 3-D grids using matlab command "interp3", what I have is the coordinates of X,Y,Z and the values at each point. The dimension of x,y,z is 76*36*16 and the sampling positions stored in vectors x, y, and z are increasing.

x y z the values at each point the commands I use to interpolate the grids are as belows: [x_out,y_out,z_out]=meshgrid(-310:5:310,-165:5:205,-70:5:5);

vel_grid=interp3(x_3d,y_3d,z_3d,vel,x_out,y_out,z_out);

and the error message: your input grid is invalid Meshgrid.

I can't figure where is wrong about my input grids, the sampling positions stored in vectors x, y, and z are increasing. What conditions should my input grids still satisfy?

1 Answers

Since your 3-D grids are irregular you cannot use interp3 which supposes that your initial data is in a proper meshgrid order.

for example

x = rand(76,36,16);
y = rand(76,36,16);
z = rand(76,36,16);
v = rand(76,36,16);
slice(x,y,z,v,0,0,0);

will result in

Error using interp3 (line 147)
Input grid is not a valid MESHGRID.
Error in slice (line 104)
    vi = interp3(x,y,z,v,xi,yi,zi,method); 

However you can use scatteredInterpolant as such

F =scatteredInterpolant(x_3d(:),y_3d(:),z_3d(:),vel(:)); 
[x_out,y_out,z_out]=meshgrid(-310:5:310,-165:5:205,-70:5:5);
v_out = F(x_out,y_out,z_out);
xslice = [0];
yslice = [0]; 
zslice = [,0];
slice(x_out,y_out,z_out,vel(:),xslice,yslice,zslice)
Related