Getting Started | ![]() ![]() |
Creating a Plot
The plot
function has different forms, depending on the input arguments. If y
is a vector, plot(y)
produces a piecewise linear graph of the elements of y
versus the index of the elements of y
. If you specify two vectors as arguments, plot(x,y)
produces a graph of y
versus x
.
For example, these statements use the colon
operator to create a vector of x
values ranging from zero to 2, compute the sine of these values, and plot the result.
x = 0:pi/100:2*pi; y = sin(x); plot(x,y)
Now label the axes and add a title. The characters \pi
create the symbol .
xlabel('x = 0:2\pi') ylabel('Sine of x') title('Plot of the Sine Function','FontSize',12)
![]() | Graphics | Multiple Data Sets in One Graph | ![]() |