MATLAB Answers

How do I extract the output equation from a cfit object in Curve Fitting Toolbox 2.0 (R2009a)?

65 views (last 30 days)
I used the curve fitting tool to generate MATLAB code for the fitting in Curve Fitting Toolbox 2.0 (R2009a). This code contains an object called 'cf_'. I would like to extract the fitted equation from this object, with the fitted values of the parameters? For example, I want to label plots with the equation.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 22 Jan 2010
There is no direct way to obtain the equation with the substituted parameter values from the 'cfit' object in Curve Fitting Toolbox 2.0 (R2009a). However, as a workaround, you can generate a string representation of the curve from a 'cfit' object, 'cf':
eq = formula(cf); %Formula of fitted equation
parameters = coeffnames(cf); %All the parameter names
values = coeffvalues(cf); %All the parameter values
for idx = 1:numel(parameters)
param = parameters{idx};
l = length(param);
loc = regexp(eq, param); %Location of the parameter within the string
while ~isempty(loc)
%Substitute parameter value
eq = [eq(1:loc-1) num2str(values(idx)) eq(loc+l:end)];
loc = regexp(eq, param);

More Answers (0)




Community Treasure Hunt

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

Start Hunting!