Documentation Center

  • Trial Software
  • Product Updates

refline

Add reference line to plot

Syntax

refline(m,b)
refline(coeffs)
refline
hline = refline(...)

Description

refline(m,b) adds a reference line with slope m and intercept b to the current axes.

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.

hline = refline(...) returns the handle hline to the line.

Examples

expand all

Add a Reference Line at the Mean

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 .

scatter(x,y,25,'b','*')

Superimpose a least-squares line on the scatter plot.

lsline

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.

See Also

| |

Was this topic helpful?