How to identify and erase the cells with the error "Error using fit>iFit (line 348). NaN computed by model function, fitting cannot continue" in an array?
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Angelavtc
el 15 de Dic. de 2021
Comentada: Ive J
el 16 de Dic. de 2021
Dear community,
I have an array (720*1 cell) where in each cell, I have a set of variables x and y. I am estimating the best fit curve for each set. However, my loop stops and gives me the error: "Error using fit>iFit (line 348). NaN computed by model function, fitting cannot continue. Try using or tightening upper and lower bounds on coefficients."
How to identify all the cells with this error and remove them from the array? This is the code that I use:
ft1= fittype( 'power2');
for k = 1 : length(Array_january)
fit_curve{k}= fit(x{k},y{k},ft1);
end
Thank you in advance!
6 comentarios
Respuesta aceptada
Ive J
el 16 de Dic. de 2021
ft1= fittype( 'power2');
fit_curve = cell(length(Array_january), 1); % never forget preallocation!
for k = 1:length(Array_january)
try
fit_curve{k} = fit(x{k}, y{k}, ft1);
catch
fprintf('error encountered index:%d\n', k)
end
end
failedIdx = find(cellfun(@isempty, fit_curve));
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Smoothing 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!