Graphics Programs Reference
In-Depth Information
x = 0:.1:2*pi;
y = sin(x);
plot(x,y)
The first line uses the colon operator to generate a vector
x
of numbers
running between 0 and 2
π
with increment 0.1. The second line calculates
the sine of this array of numbers, and calls the result
y
. The third line
produces a plot of
y
against
x
. Go ahead and produce the plot. You
should get a separate window displaying this plot. We have done in three
lines of matlab what it took us seven lines to do using the Fortran
program above.
2 Typing into MATLAB
2.1 Command Line Editing
If you make a mistake when entering a matlab command, you do not
have to type the whole line again. The arrow keys can be used to save
much typing:
↑
ctrl-p Recall previous line
↓
ctrl-n Recall next line
←
ctrl-b Move back one character
→
ctrl-f Move forward one character
ctrl-
→
ctrl-r Move right one word
ctrl-l Move left one word
home ctrl-a Move to beginning of line
end ctrl-e Move to end of line
esc ctrl-u Clear line
del ctrl-d Delete character at cursor
backspace ctrl-h Delete character before cursor
ctrl-k Delete (kill) to end of line
If you finish editing in the middle of a line, you do not have to put the
cursor at the end of the line before pressing the return key; you can press
return when the cursor is anywhere on the command line.
ctrl-
←
2.2 Smart Recall
Repeated use of the
key recalls earlier commands. If you type the
first few characters of a previous command and then press the
↑
↑
key
