MATLAB: Creating a scatter plot with smooth line for small dataset MATLAB I have a small dataset like this: x = [1 2 3 4 5]; y = [0.1 0.5 0.3 0.7 0.2]; I would like to plot them with a smooth line (not a straight line) like what we can do in Excel. Which command can do this? Thanks in advance Best Answer Use spline.xq=1:0.01:5;s=spline(x,y,xq);plot(x,y,'o',xq,s,'-') Related SolutionsMATLAB: Interpolation with a smooth curve https://www.mathworks.com/help/matlab/ref/interp1.html#d120e628896 t = [0 0.5 1.0 6.0 7.0 9.0];y = [0 1.6 2.0 2.0 1.5 0];y_when_t_is_4 = interp1(t,y,4);xx=linspace(t(1),t(end),1000);yy=interp1(t,y,xx,'spline'); % use whatever method suits you the bestplot(t,y,'o',xx,yy) MATLAB: Adding vertical line to graph at certain height I'd use the stem function. First, generate some sample data and plot it. Turn hold on so we can add the stem plot later.x = 1:10;y = x.^2;plot(x, y, '-');hold onFor the selected stem locations, determine the corresponding y values.xx = 2:1.75:9;yy = interp1(x, y, xx);Plot the stems.s = stem(xx, yy);You can adjust various properties of the stems using s. For instance, to make the markers larger magenta squares:s.Marker = 's';s.MarkerSize = 12;s.MarkerFaceColor = 'm'; Related QuestionSpline with non monotonic axis
Best Answer