% Our first plot x = linspace(0,2*pi,100); % get 100 evenly spaced values between 0 and 2 pi y = sin(x); % Compute the sine at these points and store in variable y plot(x,y) % plot the resultsThe

`linspace`

command creates 100 evenly
spaced points starting at zero and ending at . This is similar to the
thing you tried in Sec. 1.4.1 (e.g., `x=[0:2*pi/100:2*pi]`

)
except that instead of choosing the step size explicitly, `linspace`

allows you to choose the `plot`

command then plots `y`

vs. `x`

.
(See Figure 2.1.) The plot is displayed in a separate window
called `Figure No. 1`

.
You could have also used the plot command this way `plot(x,sin(x))`

without explicitly storing the function values in `y`

. Try it.
By default, MATLAB plots the data by connecting the individual data
points. The plot command can be changed so that only the points are drawn
instead of lines. Try `plot(x,y,'o')`

(the letter ``oh'' between
single quotes). Now try `plot(x,y,'-*')`

. This tells MATLAB to
connect the points with a dotted line `plot(x,y,'r-*')`

. A
list of all the style options that can be used with plot are summarized in
Table 2.1. You can also see them by typing
`help plot`

. Experiment with three or four different plot styles of
your own design.
Color-style options | Marker-style options | Line-style options | |||

`b` |
blue | . | point | - | solid |

`g` |
green | o | circle | : | dotted |

`r` |
red | x | cross | -. | dashdot |

`c` |
cyan | + | plus | - | dashed |

`m` |
magenta | * | asterisk | ||

`y` |
yellow | s | square | ||

`k` |
black | d | diamond | ||

v | triangle (down) | ||||

`^` |
triangle (up) | ||||

`<` |
triangle (left) | ||||

`>` |
triangle (right) | ||||

p | 5-pointed star | ||||

h | 6-pointed star |

We can also add labels to the axes, control the plotting range, change the aspect ratio of the plot, etc. For example, try the following:

% Making our first plot fancier x = linspace(0,2*pi,100); % get 100 evenly spaced values between 0 and 2 pi y = sin(x); % Compute the sine at these points and store in variable y plot(x,y,'r-',x,y,'x') % plot the results with a red line and blue crosses axis square % Make the plot square xlabel('angle \theta') % Label the x axis ylabel('sin(\theta)') % Label the y axis title('Pretty plot of a sine curve') % Add a title label to the plot axis([0 2*pi -1.1 1.1]) % Set the x and y ranges of the plotIf it's unclear what any of the commands do, try looking them using the help command.