MATLAB: Connecting Data points in a smooth curve

plot

How can I connect 2D data points in a smooth curve given that I can't use spline because it requires my x elements to be unique?

Best Answer

You can do this task by applying the method used in the 2nd example in spline function help page.
The following is an example:
% Your data
x = [2 4 5 2 8 5];
y = [15 6 17 28 90 80];
% Cubic spline data interpolation
t = 1:numel(x);
xy = [x;y];
pp = spline(t,xy);
tInterp = linspace(1,numel(x));
xyInterp = ppval(pp, tInterp);
% Show the result
figure
plot(x,y,'o:')
hold on
plot(xyInterp(1,:),xyInterp(2,:))
legend({'Original data','Spline interpolation'},'FontSize',12)