%% Akima Interpolation with Piecewise Polynomial Structure
%
% Create vectors for the sample points x and values at those points y. Use makima to construct a piecewise polynomial structure for the data.

x = -5:5;
y = [1 1 1 0 0 1 1 2 2 2 2];
pp = makima(x,y)

% The structure contains the information for 10 polynomials of order 4 that span the data. pp.coefs(i,:) contains the coefficients for the polynomial that is valid in the region defined by the breakpoints [breaks(i) breaks(i+1)].
%
% Use the structure with ppval to evaluate the interpolation at several query points, and then plot the results. In regions with three or more constant points, the Akima algorithm connects the points with a straight line.

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

% Copyright 2019 The MathWorks, Inc.