필터 지우기
필터 지우기

NaN/Inf/Complex value warning using "fit"

조회 수: 13 (최근 30일)
Fabs
Fabs 2016년 3월 16일
편집: Stephan 2018년 6월 21일
Hi all,
I'm interpolating between points using "fit" and get the warning
Warning: NaN, Inf, or complex value detected in startpoint;
choosing random starting point instead.
> In curvefit.attention.Warning/throw (line 30)
In fit>iFit (line 299)
In fit (line 108)
In fit_test (line 12)
The things is, (I'm pretty sure) there is no NaN, Inf, or complex value involved. Also weird, the fit seems to be different every time I execute the code (and goes completely haywire from time to time). If the first row in the data is removed, the warning disappears.
I included a code snippet that replicates my problem:
clear
close
% data
data = [1,4.26993;2,3.316751;3,3.130543;4,2.785851;5,2.462480;6,2.220899;7,1.991443;8,1.713285;9,1.591862;10,1.426485;11,1.329915;12,1.212978;13,1.163305;14,1.099329;15,1.042767;16,0.9620282;17,0.9086622;18,0.8804317;19,0.8365277;20,0.8281681;21,0.7897473;196,0.08825890;197,0.08764152;198,0.08784707;199,0.08867170;200,0.09054118];
% if first row is removed, no warning appears
% data(1,:) = [];
% fit two-term exponential function to data
data_fit = fit(data(:,1),data(:,2),'exp2');
% plot fitted data and curve
figure
plot(data_fit,data(:,1),data(:,2),'predfunc')
Any ideas? Thanks!

답변 (3개)

Antoine de Comité
Antoine de Comité 2016년 11월 16일
I have the same problem and i'm pretty sure there is no NaN, Inf or complex values in my data. Did you find what was the problem?

Stephan
Stephan 2018년 6월 21일
Hi,
if you do not specify any start points, this can happen, because the start Points are choosen by a heuristic normally. You can avoid this warning by adding a vector for the start point option:
data_fit = fit(data(:,1),data(:,2),'exp2', 'StartPoint',[0,0,0,0]);
In your case this example will work without a warning.
Best regards

Jos (10584)
Jos (10584) 2018년 6월 21일
Your model is ill-suited to this set of data, as you can verify by checking the output of data_fit. When you provide a proper starting point, the warning naturally disappears:
data_fit = fit(data(:,1),data(:,2),'exp2','Startpoint',[0 1 0 1]);
  댓글 수: 1
Stephan
Stephan 2018년 6월 21일
편집: Stephan 2018년 6월 21일
Note that with [0 1 0 1] as start point you get this result:
using [0 0 0 0] will give:
Best regards
Stephan

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by