How to get interploated values corresponding to the query point in MatLab? - spline -- MatLab

 How to get interploated values corresponding to the query point in MatLab? - spline -- MatLab

How to get interploated values corresponding to the query point in MatLab? 

[Ans]

spline

[Description]

spline is abbrevaition of sample point linearly interpolation. (I guess.)

(1)

s = spline(x,y,xq);

It will return a vector of interpolated values s corresponding to the query points in xq. The values of s are determined by cubic spline interpolation of x and y.

(2)

pp = spline(x,y);

It will return a piecewise polynomial structure for use by ppval and the spline utility unmkpp.


more details on:

Cubic spline data interpolation - MATLAB spline (mathworks.com)

code

clear
clc
help spline;
%spline example1
%fig(a)
x = [0 1 2.5 3.6 5 7 8.1 10];
y = sin(x);
xx = 0:.25:10;
yy = spline(x,y,xx);
plot(x,y,'o',xx,yy)

%spline example2
%fig(b)
x = -4:4;
y = [0 .15 1.12 2.36 2.36 1.46 .49 .06 0];
cs = spline(x,[0 y 0]);
xq = linspace(-4,4,101);
figure
plot(x,y,'o',xq,ppval(cs,xq));

output


fig(a)

                                    fig(b)

Comments