Lec 1
Lec 1
Lec 1
Tariq Hussein
MatLab Programming
Syllabus:
- Introduction
- Arithmetic operations with scalars
- Display formats
- Built-in functions
- Script files
- Creating one and two dimensional arrays
- Array addressing (Vector, Matrix)
- Script files for managing data
- Two dimensional plots
- Relational and logical operators
References:
- MatLab: An introduction with applications, 5th Edition, Amos Gilat, 2015.
Mittal, 2014.
2014.
MatLab programming Dr. Tariq Hussein
Introduction
This is an interactive environment where you can start entering commands and
obtain results instantly.
MatLab programming Dr. Tariq Hussein
Command Window: The Command Window is MATLAB 's main window and
opens when MATLAB is started. It is convenient to have the Command Window as
the only visible window. This can be done either by closing all the other windows,
or by selecting Command Window Only in the menu that opens when the Layout
MatLab programming Dr. Tariq Hussein
icon on the Toolstrip is selected. To close a window, click on the pulldown menu at
the top right-hand side of the window and then select Close.
Editor Window: The Editor Window is used for writing and editing programs. This
window is opened by clicking on the New Script icon in the Toolstrip, or by clicking
on the New icon and then selecting Script from the menu that opens. An example of
an Editor Window is shown in the figure below.
MatLab programming Dr. Tariq Hussein
Help Window: The Help Window contains help information. This window can be
opened from the Help icon in the Toolstrip of the Command Window or the toolbar
of any MATLAB window. The Help Window is interactive and can be used to obtain
information on any feature of MATLAB. The figure below shows an open Help
Window.
MatLab programming Dr. Tariq Hussein
• Several commands can be typed in the same line. This is done by typing a comma
between the commands. When the Enter key is pressed, the commands are executed
in the order from left to right.
• It is not possible to go back to a previous line that is displayed in the Command
Window, make a correction, and then re-execute the command.
• A previously typed command can be recalled to the command prompt with the up
arrow key (↑). When the command is displayed at the command prompt, it can be
modified if needed and then executed. The down-arrow key (↓) can be used to move
down the list of previously typed commands.
• If a command is too long to fit in one line, it can be continued to the next line by
typing three periods ... (called an ellipsis) and pressing the Enter key. The
continuation of the command is then typed in the new line. The command can
continue line after line up to a total of 4,096 characters.
When the symbol % (percent) is typed at the beginning of a line, the line is
designated as a comment. This means that when the Enter key is pressed the line is
not executed. This has no effect on the execution of the command. Comments are
frequently used in a program to add descriptions or to explain the program.
The clc command:
The clc command (type clc and press Enter) clears the Command Window. After
typing in the Command Window for a while, the display may become very long.
Once the clc command is executed, a clear window is displayed. The command does
MatLab programming Dr. Tariq Hussein
not change anything that was done before. For example, if some variables were
defined previously, they still exist and can be used. The up-arrow key can also be
used to recall commands that were typed before.
The Command History Window:
The Command History Window lists the commands that have been entered in the
Command Window. This includes commands from previous sessions. A command
in the Command History Window can be used again in the Command Window. By
double-clicking on the command, the command is re-entered in the Command
Window and executed. It is also possible to drag the command to the Command
Window, make changes if needed, and then execute it. The list in the Command
History Window can be cleared by selecting the lines to be deleted and then right-
clicking the mouse and selecting Delete Selection. The whole history can be deleted
by right-clicking the mouse and selecting choose Clear Command History in the
menu that opens