Ministry of Higher Education
Kabul University
Engineering Faculty
Civil Engineering Department
Course of Computer Programming (MATLAB)
Introduction to MATLAB
Prepared By: Rahmatullah MAWLANY, [Link].S.E. 1
Introduction
• MATLAB is a powerful language for technical
computing.
• The name MATLAB stands for MATrix LABoratory,
because its basic data element is a matrix (array).
• MATLAB can be used for math computations,
modeling and simulations, data analysis and processing,
visualization and graphics, and algorithm development.
2
Starting with MATLAB
• When the program starts, the MATLAB desktop window opens with the
default layout.
• The default layout consists of the following three windows that are displayed
under the Tool strip.
1. Command Window (larger window at the center)
2. Current Folder Window (on the left)
3. Workspace (on the left)
3
Windows and Their Functions
window Purpose
Command Window Main window, enters variables, runs programs.
Figure Window Contains output from graphic commands.
Editor Window Creates and debugs script and function files.
Help Window Provides help information.
Command History Window Logs commands entered in the Command Window.
Workspace Window Provides information about the variables that are stored.
Current Folder Window Shows the files in the current folder.
4
Notes for Working in the Command Window
• To type a command, the cursor must be placed next to the command prompt
( >> ).
• Once a command is typed and the Enter key is pressed, the command is
executed.
• Several commands can be typed in the same line. This is done by typing a
comma between the commands.
• It is not possible to go back to a previous line that is displayed in the
Command Window.
5
Notes for Working in the Command Window
• A previously typed command can be recalled to the command prompt with
the up-arrow key.
• If a command is too long to fit in one line, it can be continued to the next
line by typing three dots ... (called an ellipsis) and pressing the Enter key.
• When a command is typed in the Command Window and the Enter key is
pressed, the command is executed. If a semicolon ( ; ) is typed at the end of
a command, the output of the command is not displayed.
6
Notes for Working in the Command Window
• When the symbol % 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.
• The clc command (type clc and press Enter) clears the Command Window.
7
Arithmetic Operations with Scalars
8
Orders of Precedence
Precedence Mathematical Operation
First Parentheses. For nested parentheses, the innermost are executed first.
Second Exponentiation
Third Multiplication, division (equal precedence)
Forth Addition and subtraction