NaN/Inf/Complex value warning using "fit"
8 次查看(过去 30 天)
显示 更早的评论
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!
0 个评论
回答(3 个)
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?
0 个评论
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
0 个评论
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!