Extracting values from a smoothing spline fit

조회 수: 32 (최근 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 CenterFile Exchange에서 Get 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