function myfit = createFit(x,yy)
%CREATEFIT Create plot of data sets and fits
% CREATEFIT(X,YY)
% Creates a plot, similar to the plot in the main Curve Fitting Tool,
% using the data that you provide as input. You can
% use this function with 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 data sets: 1
% Number of fits: 1
% Data from data set "yy vs. x":
% X = x:
% Y = yy:
% Unweighted
% Auto-generated by MATLAB on 17-Dec-2010 21:03:21
% Set up figure to receive data sets and fits
f_ = clf;
figure(f_);
set(f_,'Units','Pixels','Position',[494 176 680 491]);
% Line handles and text for the legend.
legh_ = [];
legt_ = {};
% Limits of the x-axis.
xlim_ = [Inf -Inf];
% Axes for the plot.
ax_ = axes;
set(ax_,'Units','normalized','OuterPosition',[0 0 1 1]);
set(ax_,'Box','on');
axes(ax_);
hold on;
% --- Plot data that was originally in data set "yy vs. x"
x = x(:);
yy = yy(:);
h_ = line(x,yy,'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} = 'yy vs. x';
% Nudge axis limits beyond data limits
if all(isfinite(xlim_))
xlim_ = xlim_ + [-1 1] * 0.01 * diff(xlim_);
set(ax_,'XLim',xlim_)
else
set(ax_, 'XLim',[-2.04, 2.04]);
end
% --- Create fit "fit 1"
ok_ = isfinite(x) & isfinite(yy);
if ~all( ok_ )
warning( 'GenerateMFile:IgnoringNansAndInfs',...
'Ignoring NaNs and Infs in data.' );
end
st_ = [0.94699999999999995 0.38500000000000001 0.83899999999999997 ];
ft_ = fittype('a*b.^x+c*x.^2',...
'dependent',{'y'},'independent',{'x'},...
'coefficients',{'a', 'b', 'c'});
% Fit this model using new data
cf_ = fit(x(ok_),yy(ok_),ft_,'Startpoint',st_);
% Alternatively uncomment the following lines to use coefficients from the
% original fit. You can use this choice to plot the original fit against new
% data.
% cv_ = { 9.9504541371165054, 3.9930448940959291, 3.1481581887763213};
% cf_ = cfit(ft_,cv_{:});
% Plot this fit
h_ = plot(cf_,'fit',0.95);
set(h_(1),'Color',[1 0 0],...
'LineStyle','-', 'LineWidth',2,...
'Marker','none', 'MarkerSize',6);
% Turn off legend created by plot method.
legend off;
% Store line handle and fit name for legend.
legh_(end+1) = h_(1);
legt_{end+1} = 'fit 1';
% --- Finished fitting and plotting data. Clean up.
hold off;
% Display legend
leginfo_ = {'Orientation', 'vertical', 'Location', 'NorthEast'};
h_ = legend(ax_,legh_,legt_,leginfo_{:});
set(h_,'Interpreter','none');
% Remove labels from x- and y-axes.
xlabel(ax_,'');
ylabel(ax_,'');
myfit = cf_ % 这个句子是作者添加的用于输出拟合后的结构
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论














收起资源包目录





































































































共 130 条
- 1
- 2
资源评论

- 酒千殇2018-09-16好!好!好!好

cquc_2008
- 粉丝: 0
- 资源: 3
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助


安全验证
文档复制为VIP权益,开通VIP直接复制
