从样条拟合中获取 y 值

Getting y values back from spline fit

我使用 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 );

只需使用feval:

y = feval(fitresult,x); 

或者只使用

y = fitresult(x);