Problem with griddata giving NaN

조회 수: 23 (최근 30일)
David E.S.
David E.S. 2021년 8월 16일
댓글: Walter Roberson 2021년 8월 16일
Let's supose I have three points , , . In each point I have a data of temperature in multiple times. Here I offer a simplification of this problem:
lat = [27.5 29.3 30.1
27.5 29.3 30.1
27.5 29.3 30.1]; % Matrix of latitudes. Col1 = lat1, Col2 = lat2, Col3 = lat3.
lon = [16.5 18.9 19.9
16.5 18.9 19.9
16.5 18.9 19.9]; % Matrix of longitudes. Col1 = lon1, Col2 = lon2, Col3 = lon3.
temp = [23.5 27.8 30.5
25.9 21.3 45.8
54.3 20.1 10.4]; % i.e., temp(1,1) corresponds to (27.5,16.5), temp(1,2) corresponds to (29.3,18.9)...
time = [10 10 10
20 20 20
30 30 30]; % The first row of each matrix was measured at time 10.
Now, I want to find the temperature in , and .
latQ = 28;
lonQ = 19.3;
timeQ = 25.3;
griddata(lat, lon, time, temp, latQ, lonQ, timeQ,'linear')
ans = NaN
Why does griddata return NaN if my query points are "inside the limits"?
  댓글 수: 1
KSSV
KSSV 2021년 8월 16일
This is an extrapolation, the interpolated point do not lie in the intervel of given points.

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2021년 8월 16일
latQ = 28;
If you look at your latitudes, then 28 only occurs somewhere between the first and second column. All of your other factors must be between the first and second columns to have a potential match
lonQ = 19.3;
That is only between the second and third column.
timeQ = 25.3;
That could be anywhere in the temp array
You just do not have any data for columns 1 and 2 latitude in combination with columns 1 and 2 longitude, so you are doing an extrapolation.
  댓글 수: 4
David E.S.
David E.S. 2021년 8월 16일
I have tried griddedInterpolant, but the problem is that I have only three points, and the grid generated with ngrid creates additional points in which I don't have information. Do you have any idea to do that?
Walter Roberson
Walter Roberson 2021년 8월 16일
Your data is not suitable for the kind of interpolation you want to do.
Your query latitude represents a straight line between the first and second column of lat. You can extend that straight line, but with the values being consistent the way they are, any reasonable extrapolation method is going to continue the straight line. There is no curve in lat values that could associate that query value to the left or right of the straight line it is implied to be at right now.
Likewise, your query long represents a straight line between the second and third columns, and there is no reasonable extrapolation that would produce anything other than a straight line.
These two are not compatible. There is nowhere that the extrapolation could reach.
Time has the opposite orientation, so your query time is a horizontal line in that matrix. That horizontal line can intersect the vertical line for the latitude, and the vertical line for the longitude, but there is no way to get all three of those to intersect.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

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

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by