绘制优化曲线 Matlab

plot optimized curve Matlab

有 2 个向量 vec_x 和 vec_y,我使用非线性最小二乘法进行拟合,如下所示:

%%myfunction.m
function F = myfun(x,vec_x)
    F = 10*(erfc((x(1)+x(2)*vec_x)/sqrt(2))/2);  
end
%%console 
options = optimoptions('lsqcurvefit','Algorithm','levenberg-marquardt');
x = lsqcurvefit(@myfun, [0 1], vec_x, vec_y,[],[],options); %here i obtain x(1) and x(2).

当我想用相关点绘制拟合曲线时(vec_x .vs vec_y),我是这样执行的:

y_fit=10*erfc((x(1)+x(2)*vec_x)/sqrt(2))/2
plot(vec_x,y_fit)

问题是我有一条奇怪的曲线,与我在使用 Matlab 的 "Curv-fit App" 工具时自动拥有的曲线不相似(我使用与控制台相同的自定义函数和向量)。

在曲线拟合 GUI 中,我得到了这个:见下图 snapshot-curveFitting-GUI

我怎样才能有正确的情节,这样我才能更好地管理情节?

我在Matlab的文档上找到了答案。为了从 Cftool 绘制曲线拟合,我们应该 select 文件 -> 生成代码。 Curve Fitting 应用程序从当前会话生成代码并在 MATLAB 编辑器中显示文件。该文件包括当前会话中的所有拟合和绘图。我们必须执行代码才能获得情节。

这是由 Matlab 生成的代码:

function [fitresult, gof] = createFit_MSSI_Venus(RockerArm, mos)
%CREATEFIT1(ROCKERARM,MOS)
%  Create a fit.
%
%  Data for 'Psychometric curve fitting MSSI-RockeArm 3D mesh' fit:
%      X Input : RockerArm
%      Y Output: mos
%  Output:
%      fitresult : a fit object representing the fit.
%      gof : structure with goodness-of fit info.
%
%  See also FIT, CFIT, SFIT.

%  Auto-generated by MATLAB on 08-Jan-2016 15:40:41


%% Fit: 'Psychometric curve fitting MSSI-RockeArm 3D mesh'.
[xData, yData] = prepareCurveData( RockerArm, mos );

% Set up fittype and options.
ft = fittype( 'erfc((a+b*x)/sqrt(2))/2', 'independent', 'x',  
'dependent', 'y' );

opts = fitoptions( 'Method', 'NonlinearLeastSquares' );
opts.Algorithm = 'Levenberg-Marquardt';
opts.Display = 'Off';
opts.StartPoint = [0.655477890177557 0.171186687811562];

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

% Plot fit with data.
figure( 'Name', 'Psychometric curve fitting MSSI-RockeArm 3D mesh' );
h = plot( fitresult, xData, yData);
set(h, 'Markersize',20);
legend( h, 'mos vs. RockerArm', 'Psychometric curve fitting MSSI-        
RockeArm 3D mesh', 'Location', 'NorthEast' );

% Label axes
xlabel MSSI-RockerArm 3D mesh
ylabel mos
grid on

再次感谢