Add reference line to plot
hline = refline(...)
refline(coeffs), where coeffs is a two-element coefficient vector, adds the line
y = coeffs(1)*x + coeffs(2)
to the figure.
refline with no input arguments is equivalent to lsline.
Generate sample data for independent variable x and a dependent variable y .
x = 1:10; y = x + randn(1,10);
Create a scatter plot of x and y .
Superimpose a least-squares line on the scatter plot.
Add a reference line at the mean of the scatter and its least-squares line.
mu = mean(y); hline = refline([0 mu]); set(hline,'Color','r')
The red line shows the reference line at the mean of data.