Graphs

>> figureGraphs are drawn with the command

`plot`

. The command
>> plot(v)where

>> plot(v,w)with

>> plot(v,w,x,y)plots the points (

To determine the appearance of your graph, after plotting a vector you can add the color and linestyle of graph. For example, the command

>> plot(x,y,'r--')will plot

`help plot`

to see other line, marker and color options.
Suppose that we want to draw the graph of the function

>> x = 0:2*pi/99:2*pi; >> y = (sin(x)+2*x)./(1+x.^2); >> figure >> plot(x,y)

When drawing a graph, the axes are chosen automatically. You can choose the lengths of the axes yourself with

>> axis([XMIN XMAX YMIN YMAX])which takes care that the graph is drawn in the rectangle XMIN

After each new plot command, the old plot will in general disappear. If you want to draw different plots with different plot commands in the same figure, you have to give the following command after the first plot command

>> hold onMATLAB then holds the graphs. The command

>> hold offrestores the state in which every new plot command makes the previous plot disappear.

The following commands are also important for handling the graphical screen.

You can make the graphical screen visible by either activating it, or by using the command

>> shgThe graphical screen remains the the same until either a new plot command is given or until it is erased. The command for erasing the graphical screen is

>> clfThe command

>> griddraws a grid in the graph.

>> title('title')puts the title indicated by the string between the quotes above the plot. In the example above, the title will be the word `title'.

>> text(x,y,'string')puts the text `string' at the point (x,y) of the last plot.

>> xlabel('text')writes information along the x-axis.

>> ylabel('text')does the same for the y-axis.

You can use other plot functions in MATLAB as well. The most important are given in Figure 1.1.

`bar(x)`

produces a bar-plot of vector. `plot3(x,y,z)`

produces a three-dimensional curve between the points, whose coordinates are given in the vectors, , and . `mesh(X,Y,Z)`

produces a three-dimensional surface between the grid points, whose coordinates are given in the matrices, , and . `contour(X,Y,Z)`

produces level curves inplane, such that all points on a line have the same value for z. Since the inputs in this functions are gridpoints, the inputs , , and should be matrices.

You can save a figure by selecting "File
`print`

command. Type `help print`

for additional information. When you want to be able to open and modify your figures again in MATLAB, you should save your figure as a .fig file.

Esteur 2010-03-22