Matlab Script Files Lecture
Matlab Script Files Lecture
Signal,
Spectra
and Signal
Processing
Laboratory
Programming in
MATLAB
Ems R. Roque
When the input command is executed as the script file runs, the
string is displayed in the Command Window. The string is a
message prompting the user to enter a value that is assigned to
the variable.
The user types the value and presses the enter key. This assigns
the value to the variable.
In general, vectors and arrays can also be assigned to the
variables. This is done by typing the array in the same way that
it is usually assigned to a variable.
THE OUTPUT COMMANDS
MATLAB automatically generates a display when some commands are
executed. For example, when a variable is assigned a value, or the name of
a previously assigned variable is typed and the ENTER key is pressed,
MATLAB displays the variable and its value. This type of output is not
displayed if a semicolon is typed at the end of the command line. In
addition to this automatic display, MATLAB has several commands that can
be used to generate displays. The display can be messages that provide
information, numerical data, and plots. Two commands that are frequently
used to generate output are the disp and fprintf.
The field width and precision (5.2 in the previous example) are
optional. The first number (5) is the field width that specifies
the minimum number of digit in the display. If the number to
be displayed is shorter than the field width, spaces or zeros
are added in front of the number.
The precision is the second number (2) specifies the number
of digit to be displayed to the right of the decimal point.
The last element in the formatting elements, which is
required, is the conversion character which specifies the
notation in which the number is displayed.
Step c:
When writing the data to the file is complete, the file is closed
using the fclose command.