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.https://www.mathworks.com/help/matlab/ref/spline.html#bvjdts5The following is an example:% Your datax = [2 4 5 2 8 5];y = [15 6 17 28 90 80];% Cubic spline data interpolationt = 1:numel(x);xy = [x;y];pp = spline(t,xy);tInterp = linspace(1,numel(x));xyInterp = ppval(pp, tInterp);% Show the resultfigureplot(x,y,'o:')hold onplot(xyInterp(1,:),xyInterp(2,:))legend({'Original data','Spline interpolation'},'FontSize',12) Related SolutionsMATLAB: Cubic Spline Fit-Just confirm the code right. You can verify this byplot(X,Y,,'.',x,y);legend('Samples','Spline') MATLAB: How to do cubic interpolation from given sets of data The interp1 function with the 'pchip' method is the easiest way to do this (for me, anyway).From the documentation:'pchip' Shape-preserving piecewise cubic interpolation.The Code —x=[0 1 8 12 27];y=[1 2 3 4 5];xi = linspace(min(x), max(x));yi = interp1(x, y, xi, 'pchip');figure(1)plot(xi, yi)hold onplot(x, y, 'pr', 'MarkerFaceColor','g')hold offgrid Related QuestionInterpolation method (spline)TriScatteredInterp and ScatteredInterpolant functions produce different resultsExtract data from plotDoes the INTERP1 function in MATLAB handle complex data with the “cubic” methodHow to make a plot smooth
Best Answer