You are on page 1of 1

Editing What You Have Typed

At the MATLAB prompt, you can recall, edit, and reissue previous instructions using Emacs-
or
vi-style editing instructions. The default keybindings use Emacs-style instructions. For
example,
to recall the previous instruction, type Control-p (usually written C-p for short). C-p gets its
name from the fact that you type it by holding down CTRL and then pressing p. Doing this
will
normally bring back the previous line of input. C-n will bring up the next line of input, C-b
will
move the cursor backward on the line, C-f will move the cursor forward on the line, etc.
You can also use the up- and down-arrow to navigate through previously issued instructions.
If
you retype or reissue an instruction, all the instructions that followed its initial issuance may
also
need to be reissued in their chronological order.
Arrays and Matrices
Creating an Array (Vector)
To create a new array (vector) and store it in a variable so that you can refer to it later, type
the
instruction
>> a = [1, 2, 3, 4]
MATLAB will respond by printing the array in a neatly spaced row. MATLAB can also
create
column vectors, for example
>> b = [1, 2, 3, 4]'
b =
1
2
3
4
The " ' " is a transpose instruction that in this case converts a row vector into a column
vector. Sequences can be produced as follows
>> c = 1:100;
Ending an instruction with a semicolon prevents MATLAB from printing to the screen. The
result of the above instruction would be the sequence 1, 2, 3, ..., 100 stored as an
array.
>> d = 1:5:100;
The 5 in the example above serves as a step size. The result is the sequence 1, 6,
11, ...,
96 stored as array d. If the step size is omitted (as in the first example) it is taken to be 1.

You might also like