MATLAB代码,求修改

2025-06-25 10:11:50
推荐回答(1个)
回答1:

在7.1以上版中,可用:

x=[20 29 41 41 48 48 53 54 56 57 60 63 67 71 75 80 83 88 100 101]';
y=[1.0 0.93 0.68 0.81 0.58 0.60 0.59 0.48 0.52 0.46 0.42 0.60 0.36 0.55 0.40 0.46 0.48 0.38 0.41 0.37]';

xData = x(:);
yData = y(:);

% Set up fittype and options.
ft = fittype( 'a*x^b', 'independent', 'x', 'dependent', 'y' );
opts = fitoptions( ft );
opts.Display = 'Off';
opts.StartPoint = [0.913375856139019 0.63235924622541];

% Fit model to data.
[fitresult, gof] = fit( xData, yData, ft, opts )

x1=[20:0.1:110];
h_ = plot( x1, fitresult(x1), xData, yData, '* ' );
legend off; % turn off legend from plot method call
set(h_(1),'Color',[1 0 0],...
'LineStyle','-', 'LineWidth',2,...
'Marker','none', 'MarkerSize',6);
h = legend('拟合曲线','原始数据',2,'Location','Best');
set(h,'Interpreter','none')
title('拟合图 原始数据')
xlabel( 'x' );
ylabel( 'y' );