www.gusucode.com > simulinktest 案例源码程序 matlab代码 > simulinktest/exponentialFitAndPlot.m

    function cf_ = exponentialFitAndPlot(n,rn)
%EXPONENTIALFITANDPLOT    Fits expotential model to data

n = n(:);
rn = rn(:);

% --- Create fit "fit 1"
ok_ = isfinite(n) & isfinite(rn);
if ~all( ok_ )
    warning(message('RptgenSL:rptgen_sl:ignoringNansAndInfs'));
end
st_ = [0.49752506416553999 ]; %start value
ft_ = fittype('exp(d*n)',...
    'dependent',{'rn'},'independent',{'n'},...
    'coefficients',{'d'});

% Fit this model using new data
cf_ = fit(n(ok_),rn(ok_),ft_,'Startpoint',st_);

% Or use coefficients from the original fit:
if 0
    cv_ = { 0.42991383675518463};
    cf_ = cfit(ft_,cv_{:});
end