Getting Started with MATLAB 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. The maximum number of characters allowed on a single line is 4096.

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-pRecall previous line
ctrl-nRecall next line
ctrl-bMove back one character
ctrl-fMove forward one character
ctrl-ctrl-rMove right one word
ctrl-ctrl-lMove left one word
homectrl-aMove to beginning of line
endctrl-eMove to end of line
escctrl-uClear line
delctrl-dDelete character at cursor
backspacectrl-hDelete character before cursor
ctrl-kDelete to end of line


[ Previous | Help Desk | Next ]