フィルターのクリア

Extracting values from a smoothing spline fit

42 ビュー (過去 30 日間)
Mat
Mat 2015 年 6 月 2 日
コメント済み: Mohamed 2023 年 11 月 9 日
I've created a spline fit using curve fitting
xdat = [1;2;3;4;5;6;7;8;9;10]
ydat = [2;3;5;7;9;14;24;46;57;58]
SplineFit = fit(xdat, ydat, 'smoothingspline');
I can plot this using simply
plot(fitA)
However, what I really want to do is use this plot to find the y values for x values that are not input x values. Sort of an interpolation, but using the spline fit I used.
i.e. I want to find ydat values where xdat=[1.2; 3.6; 6.2; 7.8], using SplineFit
If I were using polynomials, I know I would use the polyval function for this but I don't know what to use considering I've used a smoothing spline.
Any help appreciated

採用された回答

John D'Errico
John D'Errico 2015 年 6 月 2 日
編集済み: John D'Errico 2015 年 6 月 2 日
feval(SplineFit,xdat)
ans =
2.1463
5.9731
15.993
40.672
You could have known this by looking at what was returned. What is it?
whos SplineFit
Name Size Bytes Class Attributes
SplineFit 1x1 2088 cfit
>> help cfit
cfit Curve Fit Object
A cfit object encapsulates the result of fitting a curve to data.
Use the FIT function or CFTOOL to create cfit objects.
You can treat a cfit object as a function to make predictions or
evaluation the curve at values of X. For example to predict what
the population was in 1905, then use
load census
cf = fit( cdate, pop, 'poly2' );
yhat = cf( 1905 )
cfit methods:
coeffvalues - Get values of coefficients.
confint - Compute prediction intervals for coefficients.
differentiate - Compute values of derivatives.
feval - Evaluate at new observations.
integrate - Compute values of integral.
plot - Plot a curve fit.
predint - Compute prediction intervals for a curve fit or for
new observations.
probvalues - Get values of problem parameters.
See also: fit, fittype, sfit.
Reference page in Help browser
doc cfit
>> methods cfit
Methods for class cfit:
argnames coeffnames dependnames fitoptions integrate numcoeffs probnames type
category coeffvalues differentiate formula islinear plot probvalues
cfit confint feval indepnames numargs predint setoptions
In that list of methods, you would have seen the feval method, clearly what you need.
You would also have seen that SplineFit itself can be used as a function. Thus...
SplineFit(xdat)
ans =
2.1463
5.9731
15.993
40.672
So, read the help! It tells you a lot.
  3 件のコメント
John D'Errico
John D'Errico 2015 年 6 月 2 日
True. Things are not always obvious.
Mohamed
Mohamed 2023 年 11 月 9 日
May i please know how to use the cfit object in the simulink interface to predict output for random input values ?

サインインしてコメントする。

その他の回答 (1 件)

Image Analyst
Image Analyst 2015 年 6 月 2 日
I think that's what my attached demo does.

カテゴリ

Help Center および File ExchangeGet Started with Curve Fitting Toolbox についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by