필터 지우기
필터 지우기

Error while fitting: X, Y and WEIGHTS cannot have Inf values.

조회 수: 29 (최근 30일)
Anshuman Pal
Anshuman Pal 2019년 11월 7일
댓글: Anshuman Pal 2019년 11월 9일
I get a series of curves obtained by numerically integrating an ODE, for different values of some parameter. They look very linear on a log-log plot, so I try to fit them with a straight line:
y = log(originalY);
[curve2,gof2] = fit(x', y','poly1', 'Exclude', x < 0.73 & x > 0.75)
However, for the last curve (which has very small numbers), the fitting shows me the error: Error while fitting: X, Y and WEIGHTS cannot have Inf values. Indeed, y has -Inf values:
y
...
Columns 121 through 140
-Inf -Inf -Inf -Inf -Inf -Inf -Inf -Inf -Inf -Inf -Inf -Inf -Inf -Inf -Inf -Inf -Inf -Inf -Inf -Inf
Columns 141 through 152
-Inf -Inf -Inf -Inf -Inf -Inf -Inf -Inf -Inf -Inf -Inf -Inf
What is going on, and how can I solve this? I even tried restricting the fitting zone (see code above) to try and avoid the -Inf values. Could this be due to finite machine precision while calculating the log? Below, in the curves (with fits where possible), you can also see that the numerical integration does not extend over the full domain (upto x=1). Maybe that is also due to machine precision.
graphs.png

채택된 답변

James Kennedy
James Kennedy 2019년 11월 7일
Can you verify that you are excluding all 'Inf' y-data with your restriction on x values?
The exclude option works when using a simple case:
% Test data
x = 1:10;
y = [1 2 3 4 5 Inf Inf Inf Inf Inf]
When including all the y data, MATLAB throws the error:
'X, Y and WEIGHTS cannot have Inf values.'
[curve2,gof2] = fit(x',y','poly1')
However, when excluding all values of x greater than 5 (which covers all the Inf values for y), the fit function completes.
[curve2,gof2] = fit(x',y','poly1','Exclude',x > 5)
  댓글 수: 3
James Kennedy
James Kennedy 2019년 11월 8일
In that case, you could find the indices of the non-infinite values before plugging into you the fitting function.
For example,
% Test data
x = 1:10;
y = [1 2 3 4 5 Inf Inf Inf Inf Inf]
indx = find(~isinf(y))
[curve2,gof2] = fit(x(indx)',y(indx)','poly1')
Anshuman Pal
Anshuman Pal 2019년 11월 9일
Great! Thank you.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Get Started with Curve Fitting Toolbox에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by