MATLAB: Spline fitting a set of data

interpninterpolationscatterspline

I have a x vector 25×1 and a y vector 25×1. I want to spline between the points to extend the vector to 96×1 points. Is there a way to do this without using interp point by point… such as using x(2,1)–> x(3,1) y(2,1)–>y(3,1) to add 3 points and move on to the next point and add three until I get 96 points. I want the the original 25 points to remain in the 96×1 vector. Thanks in advance for your help, John

Best Answer

Try my demo:
% Demo to show spline interpolation.
% Clean up / initialize
clc;
close all;
clear all;
workspace; % Display workspace panel.
% Create the original knot points.
x = 1:10;
y = rand (10,1);
% Plot it and show how the line has sharp bends.
plot(x, y, '-sr', 'LineWidth', 2);
set(gcf, 'Position', get(0,'Screensize')); % Maximize figure.
% Use splines to interpolate a smoother curve,
% with 10 times as many points,
% that goes exactly through the same data points.
samplingRateIncrease = 10;
newXSamplePoints = linspace(1, 10, 10 * samplingRateIncrease);
smoothedY = spline(x, y, newXSamplePoints);
% Plot smoothedY and show how the line is
% smooth, and has no sharp bends.
hold on; % Don't destroy the first curve we plotted.
plot(newXSamplePoints, smoothedY, '-ob');
title('Spline Interpolation Demo', 'FontSize', 20);
legend('Original Points', 'Spline Points');
% Mathworks Demo code from their Help
% x = 0:10;
% y = sin(x);
% xx = 0:.25:10;
% yy = spline(x,y,xx);
% plot(x,y,'o',xx,yy)