Receiving an error when using interp2 to interpolate longitude and latitude (Error using griddedInterpolant Grid arrays must have NDGRID structure.).
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Image Analyst
il 22 Lug 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.
Risposte (1)
Paul
il 23 Lug 2023
Modificato: Paul
il 23 Lug 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 Commenti
Vedere anche
Categorie
Scopri di più su Interpolating Gridded Data in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!