matlab Curve Fitting Tool 生成的高斯拟合代码


function [fitresult, gof] = createFit(xdata, FITDATA)
%CREATEFIT(XDATA,FITDATA)
%  Create a fit.
%
%  Data for 'untitled fit 1' fit:
%      X Input : xdata
%      Y Output: FITDATA
%  Output:
%      fitresult : a fit object representing the fit.
%      gof : structure with goodness-of fit info.
%
%  另请参阅 FIT, CFIT, SFIT.

%  由 MATLAB 于 23-Aug-2023 09:42:12 自动生成


%% Fit: 'untitled fit 1'.
[xData, yData] = prepareCurveData( xdata, FITDATA );

% Set up fittype and options.
ft = fittype( 'gauss1' );
opts = fitoptions( 'Method', 'NonlinearLeastSquares' );
opts.Display = 'Off';
opts.Lower = [-Inf -Inf 0];
opts.StartPoint = [4.50092401733857 33.0078125 7.63856013608687];

% 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, 'FITDATA vs. xdata', 'untitled fit 1', 'Location', 'NorthEast' );
% Label axes
xlabel xdata
ylabel FITDATA
grid on

matlab Curve Fitting Tool 生成的高斯拟合代码_第1张图片

你可能感兴趣的:(matlab,开发语言)