Matlabwilliam hill官网
直播中

天继风

9年用户 35经验值
私信 关注
[问答]

最小二乘进行高斯拟合的matlab程序代码?

由测试得到的一组数据,运用最小二乘进行高斯拟合的matlab程序代码(二维图)?
已退回25积分

回帖(2)

DDL123

2016-5-1 22:43:46
function [fitresult, gof] = createFit(a, b)
%CREATEFIT(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 于 01-May-2016 22:45:07 自动生成


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

% Set up fittype and options.
ft = fittype( 'gauss1' );
opts = fitoptions( 'Method', 'NonlinearLeastSquares' );
opts.Display = 'Off';
opts.Lower = [-Inf -Inf 0];
opts.Robust = 'Bisquare';
opts.StartPoint = [9 6 1.51816820741628];

% 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

举报

DDL123

2016-5-1 22:44:00
function [fitresult, gof] = createFit(a, b)
%CREATEFIT(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 于 01-May-2016 22:45:07 自动生成


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

% Set up fittype and options.
ft = fittype( 'gauss1' );
opts = fitoptions( 'Method', 'NonlinearLeastSquares' );
opts.Display = 'Off';
opts.Lower = [-Inf -Inf 0];
opts.Robust = 'Bisquare';
opts.StartPoint = [9 6 1.51816820741628];

% 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

举报

更多回帖

发帖
×
20
完善资料,
赚取积分