代码之家  ›  专栏  ›  技术社区  ›  user3646105

从样条曲线拟合中获取y值

  •  3
  • user3646105  · 技术社区  · 9 年前

    我使用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 );
    
    1 回复  |  直到 9 年前
        1
  •  1
  •   Robert Seifert    9 年前

    简单使用 feval :

    y = feval(fitresult,x); 
    

    或者只是使用

    y = fitresult(x);