Extracting values from a smoothing spline fit
51 views (last 30 days)
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
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 on 2 Jun 2015
Edited: John D'Errico on 2 Jun 2015
You could have known this by looking at what was returned. What is it?
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
cf = fit( cdate, pop, 'poly2' );
yhat = cf( 1905 )
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
probvalues - Get values of problem parameters.
See also: fit, fittype, sfit.
Reference page in Help browser
>> 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...
So, read the help! It tells you a lot.