% spline_data.m puts a cubic spline through a set of data points D = [[2 1]; [5 9]; [7 6]; [12 0]]; % list of data points x = D(:,1); % x values are 1st column of D y = D(:,2); % y values are 2nd column of D xi = min(x):.1:max(x); % x values for interpolation yi = spline(x,y,xi); % interpolated y values plot(x,y,'o',xi,yi) % plot data points and interpolated curve title('Data points and cubic spline interpolation'); axis([min(xi)-1 max(xi)+1 min(yi)-1 max(yi)+1]); % choose nice axes