cfit object doesn't work with 'plot' or 'differentiate'
Show older comments
Hello,
I stored a cfit obj to hard disc. It looks like:
General model:
ans(xd) = off+amp./(1+exp(-a.*(xd-b)))
Coefficients (with 95% confidence bounds):
off = -4.047 (-4.054, -4.041)
amp = 8.179 (8.169, 8.189)
a = 4.053 (4.034, 4.073)
b = 2.271 (2.27, 2.273)
In the process of creating the obj I was able to plot it and to calculate the derivatives.
Now I want to come back to these data and tried:
>>plot(cfObj)
but receive:
Error using cfit/plot (line 111)
Error evaluating CFIT function:
Error while trying to evaluate CFIT model: obj:
Error while trying to evaluate FITTYPE function obj:
Argument must contain a string or function_handle.
For:
>>differntiate(cfObj, x)
I receive:
Error using cfit/feval (line 31)
Error while trying to evaluate CFIT model: fitobj:
Error while trying to evaluate FITTYPE function obj:
Argument must contain a string or function_handle.
Error in cfit/differentiate (line 33)
f1 = feval(fitobj,x+ms);
Can anyone please help out with that? Sure I can recreate the fit from the coefficients, but I think it is not meant to be like that.
Thanks,
Kai
2 Comments
Onno Broekmans
on 1 Jul 2013
Your fit results are definitely not useless. You can use coeffvalues(cfObj) to get the coefficient values from the fit manually, and then plot them using:
fitCoeffs = num2cell(coeffvalues(cfObj));
fitFun = @(off,amp,a,b,xd) off+amp./(1+exp(-a.*(xd-b)));
plot(x, feval(fitFun, fitCoeffs{:}, x, '-r');
(Warning: untested code, so there might be minor syntax errors in there. I'm assuming your x data is in the variable 'x').
Note that this is what plot(cfObj,x) does internally, so the results are exactly the same :)
Kai
on 1 Jul 2013
Accepted Answer
More Answers (1)
Andrei Bobrov
on 26 Jun 2013
Edited: Andrei Bobrov
on 26 Jun 2013
x = (0:.01:4)'; %
y = -4 + 8./(1+exp(4.*(x - 2))) + .5*randn(numel(x),1); % your data
ftfun = fit(x,y,fittype(@(a,b,c,d,x)a + b./(1+exp(c.*(x - d)))),...
'Startpoint',[1 1 1 1])
dft = differentiate(ftfun,x);
plot(x,[y,ftfun(x),dft])
Categories
Find more on Fit Postprocessing in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!