Graphs with MATLAB (Taken from "MATLAB for Beginners: A Gentle Approach") by Peter Kattan by Peter Kattan - Read Online

Vista previa del libro

Graphs with MATLAB (Taken from "MATLAB for Beginners - Peter Kattan

Ha llegado al final de esta vista previa. ¡Regístrese para leer más!
Página 1 de 1

Footnotes

Graphs in MATLAB

In this article we explain how to plot graphs in MATLAB. Both two-dimensional and three-dimensional graphs are presented. A graph in MATLAB appears in its own window (not on the command line). First, we will consider two-dimensional or planar graphs. To plot a two-dimensional graph, we need two vectors. Here is a simple example using two vectors x and y along with the MATLAB command plot:

>> x = [1 2 3 4 5]

x =

1     2     3     4     5

>> y = [3 9 12 10 6]

y =

3     9    12    10     6

>> plot(x,y)

The resulting graph is displayed in its own window and is shown in Figure 1. Note how the command plot was used above along with the two vectors x and y. This is the simplest use of this command in MATLAB.

We can add some information to the above graph using other MATLAB commands that are associated with the plot command. For example, we can use the title command to add a title to the graph. Also, we can use the MATLAB commands xlabel and ylabel to add labels to the x-axis and the y-axis. But before using these three commands (title, xlabel, ylabel), we need to keep the plotted graph in its window.