MATLAB: How to add trendline to scatterplot plotscatter hi, I have 2 variables with data, like x=2 1 4 68 4 5y=5 4 2 23 21 50 I want to add trendline to the scatter plot. how can I do that? Best Answer Something like thisx = [2 1 4 68 4 5]y = [5 4 2 23 21 50]p = polyfit(x, y, 1);px = [min(x) max(x)];py = polyval(p, px);scatter(x, y, 'filled')hold onplot(px, py, 'LineWidth', 2); Related SolutionsMATLAB: How to plot to some maximum axis level Add axis([0 70 -inf inf]) MATLAB: How to change the color of a single point in a scatter plot x = [ 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5];y = [ 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5];plot(x,y)hold on scatter(x(7),y(7),'r')hold off Related QuestionScatterplot
Best Answer