【问题标题】:Getting y values back from spline fit从样条拟合中取回 y 值
【发布时间】:2015-12-21 11:31:52
【问题描述】:

我使用 MATLAB 曲线拟合工具进行样条平滑拟合,并从中创建了一个函数。如何访问 Y 拟合值以便将它们输出到文件?似乎我只看到了 x 值,以及 fitresult 中的所有系数。这是matlab代码。谢谢!

function [fitresult, gof] = createFit(Freq, AmplNew)
%CREATEFIT(FREQ,AMPLNEW)
%  Create a fit.
%
%  Data for 'untitled fit 1' fit:
%      X Input : Freq
%      Y Output: AmplNew
%  Output:
%      fitresult : a fit object representing the fit.
%      gof : structure with goodness-of fit info.
%

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

% Set up fittype and options.
ft = fittype( 'smoothingspline' );
opts = fitoptions( 'Method', 'SmoothingSpline' );
opts.SmoothingParam = 0.998;

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

【问题讨论】:

    标签: matlab curve-fitting spline


    【解决方案1】:

    只需使用feval:

    y = feval(fitresult,x); 
    

    或者直接使用

    y = fitresult(x); 
    

    【讨论】:

    • 你也可以简单地做 fitresult(x)。
    猜你喜欢
    • 1970-01-01
    • 2015-08-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-05
    • 2018-12-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多