interp3 returning NaN due to machine precision at bounds
Show older comments
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
on 29 Mar 2011
You could let it extrapolate outside the region:
interp1(dataRange,data,points(8),[],'extrap')
Categories
Find more on Resizing and Reshaping Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!