NaN/Inf/Complex value warning using "fit"
8 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (3)
Antoine de Comité
el 16 de Nov. de 2016
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 comentarios
Stephan
el 21 de Jun. de 2018
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 comentarios
Jos (10584)
el 21 de Jun. de 2018
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 comentario
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!