Generate Code by Curve Fitting Tool is not working as I expected

Hello everyone,
I was doing some curve fitting with CFTool and, as I wanted to fit several datasets, I wanted to export the code from CFTool and use the function in a script. My idea was to automatize the process and call the function many times instead of doing it manually from the CFTool interface.
The problem is that when I generate the code, the function that I get can not be used with another pair of vectors.
For example, if I generate the code for a fit that used vector 'a' and 'b' I get the following function with its script:
function [fitresult, gof] = createFits(a, b)
But when I try to call the 'createFits' function with another pair of vectors in my worspace. For example, I type in the Command Window:
createFits(c, d)
I get the Errors:
Error using fit>iFit (line 340)
Inf computed by model function, fitting cannot continue.
Try using or tightening upper and lower bounds on coefficients.
Error in fit (line 108)
[fitobj, goodness, output, convmsg] = iFit( xdatain, ydatain, fittypeobj, ...
Error in createFits (line 43)
[fitresult{1}, gof(1)] = fit( xData, yData, ft, opts );
I tried to replace all the vectors 'a' and 'b' with 'c' and 'd' in the script of the function createFits, but somehow it only works with 'a' and 'b'.
Does anybody know how to modify the createFits function so I can use it with every pair of vectors that I want?

1 Comment

hello
the name of the varaibles has of course no importance
have you tried to create a dummy c equal to a and a dummy d equal to b ?
if this works, it's because your second pair of vector is maybe too way off so the fit is not doable

Sign in to comment.

Answers (0)

Categories

Products

Release

R2017b

Asked:

on 19 Oct 2021

Commented:

on 25 Oct 2021

Community Treasure Hunt

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

Start Hunting!