Getting Started with MATLAB   Search    Help Desk 

The Command Window

So far, you have been using the MATLAB command line, typing commands and expressions, and seeing the results printed in the command window. This section describes a few ways of altering the appearance of the command window. If your system allows you to select the command window font or typeface, we recommend you use a fixed width font, such as Fixedsys or Courier, to provide proper spacing.

The format Command

The format command controls the numeric format of the values displayed by MATLAB. The command affects only how numbers are displayed, not how MATLAB computes or saves them. Here are the different formats, together with the resulting output produced from a vector x with components of different magnitudes.

If the largest element of a matrix is larger than 103 or smaller than 10-3,
MATLAB applies a common scale factor for the short and long formats.

In addition to the format commands shown above

suppresses many of the blank lines that appear in the output. This lets you view more information on a screen or window. If you want more control over the output format, use the sprintf and fprintf functions.

Suppressing Output

If you simply type a statement and press Return or Enter, MATLAB automatically displays the results on screen. However, if you end the line with a semicolon, MATLAB performs the computation but does not display any output. This is particularly useful when you generate large matrices. For example

Long Command Lines

If a statement does not fit on one line, use three periods, ..., followed by Return or Enter to indicate that the statement continues on the next line. For example

Blank spaces around the =, +, and - signs are optional, but they improve readability.

Command Line Editing

Various arrow and control keys on your keyboard allow you to recall, edit, and reuse commands you have typed earlier. For example, suppose you mistakenly enter

You have misspelled sqrt. MATLAB responds with

Instead of retyping the entire line, simply press the key. The misspelled command is redisplayed. Use the key to move the cursor over and insert the missing r. Repeated use of the key recalls earlier lines. Typing a few characters and then the key finds a previous line that begins with those characters.

The list of available command line editing keys is different on different computers. Experiment to see which of the following keys is available on your machine. (Many of these keys will be familiar to users of the EMACS editor.)

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-

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 to end of line



[ Previous | Help Desk | Next ]