Problem with griddata giving NaN

23 Ansichten (letzte 30 Tage)
David E.S.
David E.S. am 16 Aug. 2021
Kommentiert: Walter Roberson am 16 Aug. 2021
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 Kommentar
KSSV
KSSV am 16 Aug. 2021
This is an extrapolation, the interpolated point do not lie in the intervel of given points.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 16 Aug. 2021
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 Kommentare
David E.S.
David E.S. am 16 Aug. 2021
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 am 16 Aug. 2021
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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Interpolation finden Sie in Help Center und File Exchange

Produkte


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by