问题
Is there any way to use cftool non-interactively. For example, given x, y and the fitting function, calling cftool to generate and returned the fitted data without using opening the toolbox GUI. Thanks
回答1:
You can use the fit
function that comes with Curve Fitting Toolbox. To find out more, type doc fit
. Or you can use cftool interactively, then use Generate Code from the File menu to create a function that uses the fit
command to repeat your interactive work programmatically. Use this as a template example.
回答2:
I don't know, but there's another way.
File/Generate Code
回答3:
function [fitresult, gof] = Custom_fit(x,y,My_Equation)
% example -->My_Equation = 'a*exp(-b*x)+c*exp(-d*x)' % y=f(x)
[xData, yData] = prepareCurveData( x, y );
% Set up fittype and options.
ft = fittype(My_Equation, 'independent', 'x', 'dependent', 'y' );
opts = fitoptions( 'Method', 'NonlinearLeastSquares' );
opts.Display = 'Off';
opts.StartPoint = [0.0376273842264444 0.821185653244809 0.81656489972889 0.961898080855054];
% Fit model to data.
[fitresult, gof] = fit( xData, yData, ft, opts );
end
code.
来源:https://stackoverflow.com/questions/10890438/how-to-use-cftool-non-interactively-in-matlab