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. Theformat
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.
x = [4/3 1.2345e-6] format short 1.3333 0.0000 format short e 1.3333e+000 1.2345e-006 format short g 1.3333 1.2345e-006 format long 1.33333333333333 0.00000123450000 format long e 1.333333333333333e+000 1.234500000000000e-006 format long g 1.33333333333333 1.2345e-006 format bank 1.33 0.00 format rat 4/3 1/810045 format hex 3ff5555555555555 3eb4b6231abfd271If the largest element of a matrix is larger than 103 or smaller than 10-3,
format
commands shown above
format compactsuppresses 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.
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
A = magic(100);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 thes = 1 -1/2 + 1/3 -1/4 + 1/5 - 1/6 + 1/7 ...
- 1/8 + 1/9 - 1/10 + 1/11 - 1/12;
=
, +
, and -
signs are optional, but they improve readability.
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
rho = (1 + sqt(5))/2You have misspelled
sqrt
. MATLAB responds with
Undefined function or variable 'sqt'.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.)