interp3 returning NaN due to machine precision at bounds

3 views (last 30 days)
I am having trouble with interp3 returning NaN's at the bounds of the data. Here is a simplified example of my issue...
data = [1 1 1 1 1 1 1 1]
dataRange = 0:0.1:0.7
points = 0:0.1:0.8
interp1(dataRange,data,points(8))
This code returns a NaN, even though points(8)=0.7, which is the upper bound of the data.
points(8)-0.7
ans =
1.1102e-016
This tells me the points(8) is actually slightly greater than 0.7 by the amount eps/2, making it out of bounds of the data, so interp1 returns NaN. I am using interp3, but interp1 gives the same results. If I instead have points be the same as dataRange, then the problem is gone. But this is a solution I'd like to avoid at this time due to the nature of the code I am writing.
Anyone have any suggestions?
I am running R2010a, Windows 7, 64-bit.
Thanks!

Answers (1)

Teja Muppirala
Teja Muppirala on 29 Mar 2011
You could let it extrapolate outside the region:
interp1(dataRange,data,points(8),[],'extrap')
  1 Comment
Mike
Mike on 30 Mar 2011
That works with interp1, but does it work with interp3? I cannot seem to get it to work. I would still like interp3 to return NaN or something else if the point is out of bounds.
I guess my issue has more to do with points(8)=0.70000000000000011102 and not 0.7. Moreover...
points(9) - 0.8
ans =
0
points(8) - 0.7
ans =
1.1102e-016
points(7) - 0.6
ans =
1.1102e-016
points(6) - 0.5
ans =
0
points(5) - 0.4
ans =
0
points(4) - 0.3
ans =
5.5511e-017
points(3) - 0.2
ans =
0
points(2) - 0.1
ans =
0
points(1) - 0.0
ans =
0

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!