필터 지우기
필터 지우기

extract value at a specific location

조회 수: 4 (최근 30일)
Meriem Deli
Meriem Deli 2016년 11월 25일
답변: Meriem Deli 2016년 11월 28일
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.

카테고리

Help CenterFile Exchange에서 Map Display에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by