Error using interp3 "Error using griddedInterpolant. Grid arrays must have NDGRID structure"

21 次查看(过去 30 天)
I am trying to interpolate observation heights from pressures in 3D space. I am using interp3 because it is generally faster than griddata, however I return this error, and I am not really sure what NDGRID structure means. I am running it in a loop as well. The following sizes of variables in interp3(X,Y,Z,V,Xq,Yq,Zq):
for ns=1:length(obs_is)
obs_hts(ns)=interp3(repmat(y_pts,[1 1 size(h,3)]),repmat(x_pts,[1 1 size(h,3)]),double(p),double(h),obs_lats(ns),obs_lons(ns),obs_pres(ns));
end
X: latitudes in 3D model space (199x199x50)
Y: longitudes in 3D model space (199x199x50)
Z: pressure in 3D model space (199x199x50)
V: heights in 3D model space (199x199x50)
Xq: observation latitude (scalar)
Vq: observation longitude (scalar)
Zq: observation pressure (scalar)
And yes, these are all double (not single) variables.

回答(2 个)

Star Strider
Star Strider 2023-8-27
The ndgrid function creates gridded data (in 2, 3, ..., n) dimehsions from its argument vectors.
Considering the nature of your problem, the interpn function might be more appropriate.
.
  10 个评论
Walter Roberson
Walter Roberson 2023-8-28
interp3() has a try/catch that tests the error generated by griddedInterpolant() and conditionally substitutes a different error message referencing meshgrid(). But perhaps the error codes got updated while the interp3() error code test did not get updated?
Paul
Paul 2023-8-28
That sounds like an odd way to handle input argument checking to interp3. Seems like that should be done at the interp3 level before the call to griddedInterpolant.
At least calling interp3 with ndgrid inputs generates the expected error
[X,Y,Z] = ndgrid(1:4);
V = X + Y + Z;
interp3(X,Y,Z,V,1.5,2.5,3.5)
Error using interp3
Input grid is not a valid MESHGRID.

请先登录,再进行评论。


Bruno Luong
Bruno Luong 2023-8-28
编辑:Bruno Luong 2023-8-29
Check with this
for ns=1:length(obs_is)
X = repmat(y_pts,[1 1 size(h,3)]);
Y = repmat(x_pts,[1 1 size(h,3)]);
Z = double(p);
if ~all(X == X(1,:,1), 'all')
if all(X == X(:,1,1), 'all') && all(Y == Y(1,:,1), 'all')
warning('You might swap X and Y')
else
error('X for ns=%d X is not meshgrid generated', ns);
end
end
if ~all(Y == Y(:,1,1), 'all')
error('Y for ns=%d Y is not meshgrid generated', ns);
end
if ~all(Z == Z(1,1,:), 'all')
error('Z for ns=%d Z is not meshgrid generated', ns);
end
end
It allows to see further why your data is incorrectly gridded for interp3

类别

Help CenterFile Exchange 中查找有关 Interpolation 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by