%example with subplots close all clear all home start = input('give initial point: ... ') final = input('give final point: ... ') step = input('give the required step: ... ') xf = start : step : final - step; yf = cos(2*pi*xf/10); xp = start : final; yp = cos(2*pi*xp/10); fig(1) = subplot(2,2,1) lin=interp1(xp,yp,xf,'linear'); plot(xf,yf,'k',xf,lin,'b'); legend ('original','linear') fig(2) = subplot(2,2,2) spl=interp1(xp,yp,xf,'spline'); plot(xf,yf,'k',xf,spl,'m'); legend ('original','spline') fig(3) = subplot(2,2,3) cub=interp1(xp,yp,xf,'pchip'); plot(xf,yf,'k',xf,cub,'c'); legend ('original','pchip') fig(4) = subplot(2,2,4) near=interp1(xp,yp,xf,'nearest'); plot(xf,yf,'k',xf,near,'g'); legend ('original','nearest') linkaxes(fig , 'xy') zoom