matlab hleg,Matlab讨论区 - 声振论坛 - 振动,动力学,声学,信号处理,故障诊断 - Powered by Discuz!...

function createFit(x,y)

%CREATEFIT Create plot of data sets and fits

%   CREATEFIT(X,Y)

%   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 "y vs. x":

%     X = x:

%     Y = y:

%     Unweighted% Auto-generated by MATLAB on 18-Apr-2011 10:56:55% Set up figure to receive data sets and fits

f_ = clf;

figure(f_);

set(f_,'Units','Pixels','Position',[578 254 688 485]);

% 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 "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_)

else

set(ax_, 'XLim',[4.75, 30.25]);

end% --- Create fit "fit 1"

ok_ = isfinite(x) & isfinite(y);

if ~all( ok_ )

warning( 'GenerateMFile:IgnoringNansAndInfs',...

'Ignoring NaNs and Infs in data.' );

end

st_ = [0.15243570612980811 -0.25709456653830987 0.033745642790019854 -0.038489626682204618 ];

ft_ = fittype('exp2');% Fit this model using new data

cf_ = fit(x(ok_),y(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_ = { 0.19159877789258178, -0.31895949786907274, 0.040716429909295873, -0.044867078417144955};

%    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_,'');

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值