Borrar filtros
Borrar filtros

extract value at a specific location

4 visualizaciones (últimos 30 días)
Meriem Deli
Meriem Deli el 25 de Nov. de 2016
Respondida: Meriem Deli el 28 de Nov. de 2016
Hello,
I am trying to extract a value at a specific point based on its latitude and longitude, I have a Temperature matrix(from a netcdf file) at different latitude and longitude I should get Temperature at a specfic location that is not figuring in the matrix I tried with interp2:
Tst=interp2(T1,lon_desired,latitude-desired)
but I get NaN
Could someone help me fix this issue.
Thanks in advance

Respuesta aceptada

dpb
dpb el 25 de Nov. de 2016
Tst=interp2(T1,lon_desired,latitude-desired)
Don't supply the coordinates of the reference T array so the values requested are outside the ranges 1:N,1:M, the dimensions of the array T1 undoubtedly. See the doc for usage details; you need the first syntax shown.
  2 comentarios
dpb
dpb el 25 de Nov. de 2016
[Moved OP Answer to Comment...dpb]
I tried to put original latitude and longitude but I got an error:
>> Tstat=interp2(longitude,latitude,T1,lon,lat)
Error using griddedInterpolant
The grid vectors do not define a grid of points that match the given values.
Error in interp2>makegriddedinterp (line 226)
F = griddedInterpolant(varargin{:});
Error in interp2 (line 136)
F = makegriddedinterp(X, Y, V, method,extrap);
I don't know what is the problem with that syntax
dpb
dpb el 25 de Nov. de 2016
Editada: dpb el 26 de Nov. de 2016
Isn't the syntax, per se, it's the data.
From the doc,
"X and Y must be monotonic, and have the same format ("plaid") as if they were produced by meshgrid. Matrices X and Y specify the points at which the data Z is given."
Hence, X,_Y_ must have same dimensions 1:1 as does Z (your T1). If you don't have regular, full-rank MxN array(), you can't use *interp2. If that is so, then perhaps griddata will suffice.
(*) It's possible with lat/long data it's full array but may not be organized such that it's not arranged in "plaid" order.

Iniciar sesión para comentar.

Más respuestas (2)

Walter Roberson
Walter Roberson el 25 de Nov. de 2016
You need to pass in the original latitude and longitude vectors as the first two arguments to interp2(). Currently you are just passing in the data matrix without giving any indication of what latitude or longitude the rows and columns correspond to.

Meriem Deli
Meriem Deli el 28 de Nov. de 2016
griddata was a solution, In fact I tried it before and I got an error because I forget to put tranpose T, Thank you all for your help.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by