从样条拟合中获取y值

时间:2015-09-24 00:37:14

标签: matlab curve-fitting spline

我使用MATLAB曲线拟合工具进行样条平滑拟合并从中创建函数。如何访问Y拟合值以便将其输出到文件中?似乎我只看到x值,以及来自fitresult的所有coefs。这是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 个答案:

答案 0 :(得分:1)

只需使用feval

y = feval(fitresult,x); 

或只是使用

y = fitresult(x);