Filter löschen
Filter löschen

extract value at a specific location

4 Ansichten (letzte 30 Tage)
Meriem Deli
Meriem Deli am 25 Nov. 2016
Beantwortet: Meriem Deli am 28 Nov. 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

Akzeptierte Antwort

dpb
dpb am 25 Nov. 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 Kommentare
dpb
dpb am 25 Nov. 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 am 25 Nov. 2016
Bearbeitet: dpb am 26 Nov. 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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (2)

Walter Roberson
Walter Roberson am 25 Nov. 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 am 28 Nov. 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.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by