Receiving an error when using interp2 to interpolate longitude and latitude (Error using griddedInterpolant Grid arrays must have NDGRID structure.).
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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
Réponses (1)
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.')
F = scatteredInterpolant(lon(:),lat(:),elevation(:));
%(longitude:171.40 , latitude:-83.51)
F(171.4,-83.51)
Check the doc page and see if that result is what you'd expect based on the sample data.
0 commentaires
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!