www.gusucode.com > curvefit 案例源码程序 matlab代码 > curvefit/CreateCustomLinearModelExample.m

    %% Create Custom Linear Model  
% To use a linear fitting algorithm, specify a cell array of terms.   

% Copyright 2015 The MathWorks, Inc.


%% 
% Identify the linear model terms you need to input to |fittype|: |a*x +
% b*sin(x) + c|. The model is linear in |a|, |b| and |c|. It has three terms
% |x|, |sin(x)| and |1| (because |c=c*1|). To specify this model you use
% this cell array of terms: |LinearModelTerms = {'x','sin(x)','1'}|. 
%
% Use the cell array of linear model terms as the input to |fittype|. 
ft = fittype({'x','sin(x)','1'})  

%% 
% Create a linear model fit type for |a*cos(x) + b|. 
ft2 = fittype({'cos(x)','1'})   

%% 
% Create the fit type again and specify coefficient names. 
ft3 = fittype({'cos(x)','1'},'coefficients',{'a1','a2'})