【问题标题】:Matlab curve fitting tool, cftool, generate code function does not give the same fitmatlab曲线拟合工具,cftool,生成代码函数不给同样的拟合
【发布时间】:2012-12-03 08:21:47
【问题描述】:

我正在使用 Matlab 的曲线拟合工具 cftool 来拟合我拥有的一组点。我面临的问题是生成代码功能不会像cftool 中产生的那样适合我。

这不是我想要的,因为我希望能够从残差图中检索数据。我也可以从cftool 复制函数并手动执行。但我不明白为什么生成的代码不会给我同样的曲线拟合。

cftool 会话文件:http://dl.dropbox.com/u/20782274/test.sfit

Matlab 生成的代码:

function [fitresult, gof] = createFit1(Velocity, kWhPerkm)
%CREATEFIT1(VELOCITY,KWHPERKM)
%  Create a fit.
%
%  Data for 'untitled fit 3' fit:
%      X Input : Velocity
%      Y Output: kWhPerkm
%  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 02-Dec-2012 16:36:19


%% Fit: 'untitled fit 3'.
[xData, yData] = prepareCurveData( Velocity, kWhPerkm );

% Set up fittype and options.
ft = fittype( 'a/(0.008*x) + c*x^2 + d*90', 'independent', 'x', 'dependent', 'y' );
opts = fitoptions( ft );
opts.DiffMaxChange = 0.01;
opts.Display = 'Off';
opts.Lower = [-Inf -Inf -Inf];
opts.MaxFunEvals = 1000;
opts.MaxIter = 1000;
opts.StartPoint = [0 0 0];
opts.Upper = [Inf Inf Inf];

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

% Create a figure for the plots.
figure( 'Name', 'untitled fit 3' );

% Plot fit with data.
subplot( 2, 1, 1 );
plot( fitresult, xData, yData, 'predobs' );
% Label axes
xlabel( 'Velocity' );
ylabel( 'kWhPerkm' );
grid on

% Plot residuals.
subplot( 2, 1, 2 );
plot( fitresult, xData, yData, 'residuals' );
% Label axes
xlabel( 'Velocity' );
ylabel( 'kWhPerkm' );
grid on

我用生成的代码得到的曲线: http://i.stack.imgur.com/65d1P.jpg

我需要的曲线: http://i.stack.imgur.com/p3Egp.jpg

那么有谁知道出了什么问题?

-编辑- 还有 Velocity 和 WhPerkm 数据文件:http://dl.dropbox.com/u/20782274/data.mat

【问题讨论】:

标签: matlab curve-fitting


【解决方案1】:

RE:我希望能够从残差图中检索数据

一种方法是:

  1. 从适合菜单中选择“保存到工作区...”
  2. 确保选中“将拟合输出保存到命名的 MATLAB 结构”。
  3. 注意变量的名称。默认为output
  4. 点击“确定”将数据发送到 MATLAB 工作区。

在 MATLAB 工作区中,残差将位于 output.residuals 中。对于您的示例,您可以通过以下方式绘制残差,例如,

>> plot( Velocity, output.residuals, '.' )

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多