Interp1 returns NaN for a value
이전 댓글 표시
I have some data (x,f(x)) where 0<=x<=1 and I have N points. I wish to obtain f for an inteverval [a,b] which is well within the limits of 0 and 1, and on my end point, I get a NaN so some reason. I think my data set goes up from 0.001 to 0.999, and the set I want values for goes between 0.05 and 0.96. There is no extrapolation required.
What's going on exactly?
댓글 수: 9
dpb
2019년 10월 8일
Show us the data and code...we can't guess.
Matthew Hunt
2019년 10월 8일
dpb
2019년 10월 8일
Then we really can't do much to help...your problem is data-specific
Matthew Hunt
2019년 10월 8일
dpb
2019년 10월 8일
It's not that we're "unwilling" but if we can't reproduce an unspecified problem, what are we supposed to do? Buy the Crystal Ball Toolbox?
I be surprised if putting a set of x,y data into a .mat file and attaching it with no identifying info or context could possibly be of any real impact to your organization.
Or, if you wish, contact me directly thru my link thru the ML Contributors link and I'll destroy anything received once the issue is resolved one way or another.
Sciora Chang
2021년 10월 25일
Have you solved this problem? I have met the exact same situation and couldn't figure out why.
dpb
2021년 10월 25일
As we told the original poster some two years ago, unless you post the data and the code, there's nothing can do beyond the general suggestions given here then -- interp1 has been around long enough that if there were some actual flaw in it, it is highly unlikely it wouldn't have been found long before now.
Attach the data at a minimum...
Michael Demkowicz
2023년 11월 21일
I've run into the same problem: interp1 returns a NaN at the endpoint of the interpolation range. I'm attaching the data to demonstrate the problem. I see NaN when I load the data and run the following commands:
nirrhor=interp1(irr,irrhor,r);
nirrhor(length(r))
"I've run into the same problem: interp1 returns a NaN at the endpoint of the interpolation range. I'm attaching the data to demonstrate the problem. I see NaN when I load the data and run the following commands"
Lets take a look:
S = load('interpdata.mat')
V = interp1(S.irr,S.irrhor,S.r)
X = find(isnan(V))
fprintf('%.42f %.42f\n', S.r([1,X]), S.irr([1,end])) % requested; supplied
The last value you requested clearly lies outside the domain of your data. It is unclear what the problem is, everything seems to be working exactly as documented and expected.
답변 (2개)
Star Strider
2019년 10월 8일
1 개 추천
You could have NaN values in your data. If so, first use the fillmissing function (R2016b and later reseases), then interp1.
댓글 수: 2
Matthew Hunt
2019년 10월 8일
Star Strider
2019년 10월 8일
If you are not extrapolating (that should only produce NaN values for the extrapolated values if you do not include a method designation and the 'extrap' argument), and there are no NaN values anywhere in your data, and we can’t see your data to test it, this will likely remain unsolved.
Chris B
2022년 8월 27일
이동: Image Analyst
2022년 8월 27일
I ran into an issue where my start and endpoints were NaN. Turns out I was defining my x and xquery values differently. For example, try this code:
x=[500:2:1100]*10^-1;
xq=[500*10^-1 :2*10^-1: 1100*10^-1];
x==xq
x ~= xq because you are comparing floats in this case. Change 10^-1 to 10^1 and you'll get x==xq. So if you're getting NaNs, try making your x and xquery both integers and then dividing to get floats afterward.
카테고리
도움말 센터 및 File Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!