extract value at a specific location

4 次查看(过去 30 天)
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

采纳的回答

dpb
dpb 2016-11-25
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 个评论
dpb
dpb 2016-11-25
[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 2016-11-25
编辑:dpb 2016-11-26
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.

请先登录,再进行评论。

更多回答(2 个)

Walter Roberson
Walter Roberson 2016-11-25
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 2016-11-28
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.

标签

Community Treasure Hunt

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

Start Hunting!

Translated by