在matlab中,你可以来选择两组数组用工具箱拟合,也可以用下面的这段M代码来
function [fitresult, gof] = createFit1(a, b)
%CREATEFIT1(A,B)
% Create a fit.
%
% Data for 'untitled fit 1' fit:
% X Input : a
% Y Output: b
% Output:
% fitresult : a fit object representing the fit.
% gof : structure with goodness-of fit info.
%
% 另请参阅 FIT, CFIT, SFIT.
% 由 MATLAB 于 04-May-2016 01:45:37 自动生成
%% Fit: 'untitled fit 1'.
[xData, yData] = prepareCurveData( a, b );
% Set up fittype and options.
ft = fittype( 'poly4' );
opts = fitoptions( 'Method', 'LinearLeastSquares' );
opts.Robust = 'Bisquare';
% Fit model to data.
[fitresult, gof] = fit( xData, yData, ft, opts );
% Plot fit with data.
figure( 'Name', 'untitled fit 1' );
h = plot( fitresult, xData, yData );
legend( h, 'b vs. a', 'untitled fit 1', 'Location', 'NorthEast' );
% Label axes
xlabel a
ylabel b
grid on
function [fitresult, gof] = createFit1(a, b)
%CREATEFIT1(A,B)
% Create a fit.
%
% Data for 'untitled fit 1' fit:
% X Input : a
% Y Output: b
% Output:
% fitresult : a fit object representing the fit.
% gof : structure with goodness-of fit info.
%
% 另请参阅 FIT, CFIT, SFIT.
% 由 MATLAB 于 04-May-2016 01:45:37 自动生成
%% Fit: 'untitled fit 1'.
[xData, yData] = prepareCurveData( a, b );
% Set up fittype and options.
ft = fittype( 'poly4' );
opts = fitoptions( 'Method', 'LinearLeastSquares' );
opts.Robust = 'Bisquare';
% Fit model to data.
[fitresult, gof] = fit( xData, yData, ft, opts );
% Plot fit with data.
figure( 'Name', 'untitled fit 1' );
h = plot( fitresult, xData, yData );
legend( h, 'b vs. a', 'untitled fit 1', 'Location', 'NorthEast' );
% Label axes
xlabel a
ylabel b
grid on
一周热门 更多>