fit1;每天进步一点点

 21:50:00

http://hi.baidu.com/rns521/blog/item/3006e94069a69d16afc3ab8d.html

分析代码;应用到实验数据;


function [cf_ ,gof ] = fit1(x,y)

%FIT1    Create plot of datasets and fits
%   FIT1(X,Y)
%   Creates a plot, similar to the plot in the main curve fitting
%   window, using the data that you provide as input.  You can
%   apply this function to the same data you used with cftool
%   or with different data.  You may want to edit the function to
%   customize the code and this help message.
%
%   Number of datasets:  1
%   Number of fits:  1


 
% Data from dataset "y vs. x":
%    X = x:
%    Y = y:
%    Unweighted
%
% This function was automatically generated on 02-May-2012 21:14:24


% Set up figure to receive datasets and fits
f_ = clf;
figure(f_);
legh_ = []; legt_ = {};   % handles and text for legend
xlim_ = [Inf -Inf];       % limits of x axis
ax_ = subplot(1,1,1);
set(ax_,'Box','on');
axes(ax_); hold on;


 
% --- Plot data originally in dataset "y vs. x"
x = x(:);
y = y(:);
h_ = line(x,y,'Parent',ax_,'Color',[0.333333 0 0.666667],...
     'LineStyle','none', 'LineWidth',1,...
     'Marker','.', 'MarkerSize',12);
xlim_(1) = min(xlim_(1),min(x));
xlim_(2) = max(xlim_(2),max(x));
legh_(end+1) = h_;
legt_{end+1} = 'y vs. x';


% Nudge axis limits beyond data limits
if all(isfinite(xlim_))
   xlim_ = xlim_ + [-1 1] * 0.01 * diff(xlim_);
   set(ax_,'XLim',xlim_)
end




% --- Create fit "fit 1"---------自行编写的拟合函数
fo_ = fitoptions('method','NonlinearLeastSquares','Algorithm','Gauss-Newton');
st_ = [100.0 1.0 3.0 50.0 ];     %%初值如何根据数据随时改变?????????、
set(fo_,'Startpoint',st_);
ft_ = fittype('a2 + (a1-a2)/(1+exp((x-x0)/c))' ,...
     'dependent',{'y'},'independent',{'x'},...
     'coefficients',{'a1', 'a2', 'c', 'x0'});


% Fit this model using new data-----------修改后+gof
[cf_ ,gof ]= fit(x,y,ft_ ,fo_);


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


% Plot this fit
h_ = plot(cf_,'fit',0.95);
legend off;  % turn off legend from plot method call
set(h_(1),'Color',[1 0 0],...
     'LineStyle','-', 'LineWidth',2,...
     'Marker','none', 'MarkerSize',6);
legh_(end+1) = h_(1);
legt_{end+1} = 'fit 1';


hold off;

legend(ax_,legh_, legt_);


--------------------------------------------------------------

y=[80 79 80 80 79 77 76 79 78 75 74 75 75 78 78 80 80 79 78 78 79 78 81 79 79 79 79 79 79 78 79 79 79 79 79 77 78 79 78 75 71 69 66 60 52 45 38 30 24 19 15 10 9 8 7 7 8 7 6 5  5 5 6 5 5 7 7 6 7 7    7 7 6 7 8 7 7 7 7 7 7 8 7 7 6 6 6 7 7 6   5 7 8 6 5 5 6 5 6 7];

ans =


     General model:
       ans(x) = a2 + (a1-a2)/(1+exp((x-x0)/c))
     Coefficients (with 95% confidence bounds):
       a1 =       78.47  (78.07, 78.87)
       a2 =       6.347  (5.984, 6.71)
       c =        2.22  (2.104, 2.337)
       x0 =       46.37  (46.24, 46.51)

你可能感兴趣的:(fit1;每天进步一点点)