Effacer les filtres
Effacer les filtres

Receiving an error when using interp2 to interpolate longitude and latitude (Error using griddedInterpolant Grid arrays must have NDGRID structure.).

5 vues (au cours des 30 derniers jours)
Hello, I have a 140x140 longitude matrix, a 140x140 latitude matrix, and a 140x140 matrix that corresponds to elevation at these longitudes and latitudes. I am trying to interpolate in order to find the elevation at specifc longitude and latitude (longitude:171.40 , latitude:-83.51) using interp2: interp2(lon,lat,elevation,171.40,-83.51);.
However I keep recieving this error:
Error using griddedInterpolant
Grid arrays must have NDGRID structure.
Error in interp2>makegriddedinterp (line 226)
F = griddedInterpolant(varargin{:});
Error in interp2 (line 134)
F = makegriddedinterp(X, Y, V, method,extrap);
Error in untitled (line 14)
interp2(lon,lat,elevation,171.40,-83.51);
I dont understand why I keep receiving this error and I cannot figure out how to fix it. I have attached the spreadsheets with the longitude, latitude, and elevation data. Any help would be greatly appreciated. Thank you!
  2 commentaires
Image Analyst
Image Analyst le 22 Juil 2023
Make it easy for people to help you by not requiring them to write code to get your variables. Post the code to read in the data.
Sasha
Sasha le 23 Juil 2023
Sorry about that. Here is the code (I've also attached the code as .m):
lon = xlsread('lon.xlsx') ;
lat = xlsread('lat.xlsx') ;
elevation = xlsread('elevation.xlsx') ;
x = interp2(lon,lat,elevation,171.40,-83.51) ;

Connectez-vous pour commenter.

Réponses (1)

Paul
Paul le 23 Juil 2023
Modifié(e) : Paul le 23 Juil 2023
lon = xlsread('lon.xlsx') ;
lat = xlsread('lat.xlsx') ;
elevation = xlsread('elevation.xlsx') ;
interp2 requires matrix inputs of sample points to be in meshgrid format. When plotted together, the sample points would bmake a nice array of points. For example
[X,Y] = meshgrid(1:5,2:2:10);
figure
plot(X,Y,'r.'),axis padded
But your data doesn't look like that
figure
plot(lon,lat,'r.')
Maybe scatteredInterpolant would be more appropriate
F = scatteredInterpolant(lon(:),lat(:),elevation(:));
%(longitude:171.40 , latitude:-83.51)
F(171.4,-83.51)
ans = 299.5649
Check the doc page and see if that result is what you'd expect based on the sample data.

Catégories

En savoir plus sur Geographic Plots dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by