%% Interpolation with Piecewise Polynomial Structure
% Create vectors for the x values and function values y, and then use pchip to construct a piecewise polynomial structure.

x = -5:5;
y = [1 1 1 1 0 0 1 2 2 2 2];
p = pchip(x,y);

%
% Use the structure with ppval to evaluate the interpolation at several query points. Plot the results.

xq = -5:0.2:5;
pp = ppval(p,xq);
plot(x,y,'o',xq,pp,'-.')
ylim([-0.2 2.2])

% Copyright 2012 The MathWorks, Inc.