Main Content

2-D line plot

`plot(`

creates
a 2-D line plot of the data in `X`

,`Y`

)`Y`

versus the corresponding
values in `X`

.

If

`X`

and`Y`

are both vectors, then they must have equal length. The`plot`

function plots`Y`

versus`X`

.If

`X`

and`Y`

are both matrices, then they must have equal size. The`plot`

function plots columns of`Y`

versus columns of`X`

.If one of

`X`

or`Y`

is a vector and the other is a matrix, then the matrix must have dimensions such that one of its dimensions equals the vector length. If the number of matrix rows equals the vector length, then the`plot`

function plots each matrix column versus the vector. If the number of matrix columns equals the vector length, then the function plots each matrix row versus the vector. If the matrix is square, then the function plots each column versus the vector.If one of

`X`

or`Y`

is a scalar and the other is either a scalar or a vector, then the`plot`

function plots discrete points. However, to see the points you must specify a marker symbol, for example,`plot(X,Y,'o')`

.

`plot(`

creates a
2-D line plot of the data in `Y`

)`Y`

versus the index
of each value.

If

`Y`

is a vector, then the*x*-axis scale ranges from 1 to`length(Y)`

.If

`Y`

is a matrix, then the`plot`

function plots the columns of`Y`

versus their row number. The*x*-axis scale ranges from 1 to the number of rows in`Y`

.If

`Y`

is complex, then the`plot`

function plots the imaginary part of`Y`

versus the real part of`Y`

, such that`plot(Y)`

is equivalent to`plot(real(Y),imag(Y))`

.

`plot(___,`

specifies line
properties using one or more `Name,Value`

)`Name,Value`

pair arguments. For a
list of properties, see Line Properties. Use this option with any
of the input argument combinations in the previous syntaxes. Name-value pair
settings apply to all the lines plotted.

returns a column vector of
chart line objects. Use `h`

= plot(___)`h`

to modify properties of a specific
chart line after it is created. For a list of properties, see Line Properties.

Use

`NaN`

and`Inf`

values to create breaks in the lines. For example, this code plots the first two elements, skips the third element, and draws another line using the last two elements:plot([1,2,NaN,4,5])

`plot`

uses colors and line styles based on the`ColorOrder`

and`LineStyleOrder`

properties of the axes.`plot`

cycles through the colors with the first line style. Then, it cycles through the colors again with each additional line style.Starting in R2019b, you can change the colors and the line styles after plotting by setting the

`ColorOrder`

or`LineStyleOrder`

properties on the axes. You can also call the`colororder`

function to change the color order for all the axes in the figure.