Lab 1
Lab 1
LAB#1:
INTRODUCTION TO MATLAB
(BASIC CONCEPTS)
Learning Objectives:
• Starting and Ending a MATLAB session.
• Learn about the major components of MATLAB environment.
• Learn to use Help Browser and help Command.
• Know about different types of files used in MATLAB.
• Know the various platforms where MATLAB can be used.
• Some other useful general commands.
Introduction:
MATLAB stands for MATRIX LABORATORY. A special purpose computer program optimized to perform
Engineering and Scientific calculations or it is a Technical programming language. It is started with simple matrix
manipulation and grown with the capability of solving any technical problem. It is a proprietary programming
language developed by Math-works. It provides a very extensive library of pre-defined functions to make technical
programming task easier and more efficient. It is superior on other languages like C, C++, FORTRAN.
MATLAB Capabilities:
Numerical computation
Data Access
Data Analysis and Visualization
Programming and Algorithm development
Application development and deployment
MATLAB MANUAL 1
SESSION: 2018-2022 CIVIL ENGINEERING DEPARTMENT
MATLAB Environment:
Command window
Command history
Workspace
Current folder
Figure window
Edit window
1. Command Window:
Whenever MATLAB is involved the main window called command window is activated. The command window
displays the command prompt “>>” and a cursor where commands are entered and are executed instantaneously on
pressing the “enter” key of the keyboard. Commands can be run by typing them in the command window.
3. Workspace:
MATLAB MANUAL 2
SESSION: 2018-2022 CIVIL ENGINEERING DEPARTMENT
A workspace is a collection of all the variables that have been generated so far in the current MATLAB session
and shows their data type and size. The workspace information can also be obtained by typing command at the
command prompt. The “who” and “whos” command will generate list of variables currently in the workspace.
Workspace stores generated variables temporarily. The workspace will be cleared when we closed the MATLAB.
All the commands executed from command window and all the script files executed from the command window
share common workspace, so they can share all the variables. Using these variables, a number of operations can be
done such as plotting by selecting a variable and right clicking the mouse and selecting the desired option from
pop-up menu.
4. Current Folder:
It contained all executed programs and save MATLAB files. In the current folder window, all the files and folder
present in the current directory will be listed. To run any file it must either be in the current directory or on the
search path. A quick way to view or change the current directory or its content is by using the current directory
field in MATLAB toolbar. For this click on “DESKTOP” on the menu bar and check the boxes to show window.
5. Edit Window:
An edit window is used to create a new program file or to modify existing files. In the window, programs can be
written, edited and save. The programs written using a MATALB editor are automatically assigned an extension
“.m” by the editor and are known as M. files. A new M. file can be created by selecting an appropriate option from
the desktop “file” menu. An existing M. file can be opened by selecting “file” from menu bar and then click
“Open” from desktop menu. The window editor is open automatically when a new M. file is created or and
existing M. file is opened.
6. Figure Window:
A figure window is a separate window with default white background and is used to display MATLAB graphics.
The result of all the graphics command executed or displayed in the figure window. There can be any number of
figure windows depending upon the system memory. To open figure window write “figure” in command window
and press enter key. A figure window is displayed.
Symbols Operations
+ Used for addition e.g. >>2+3
- Used for subtraction e.g. >>3-2
* Used for multiplication e.g. >>2*x
/ Used for division e.g. >> 2/5
^ Used for exponentiation e.g. >>2^4 →24
sqrt To find square root e.g. sqrt(4)
% Used to write comments or any statements that we do not want to execute.
pi Used for π (3.141592……)
; To terminate a line and suppress the result to display on command window
MATLAB MANUAL 3
SESSION: 2018-2022 CIVIL ENGINEERING DEPARTMENT
e.g. >>x=2;
It will not be executed
Used to define a range
e.g.
we want to write counting from 1 to 100 with gap 1, then >>1:1:100
It will display all numbers from 1 to 100.
: Generally,
Initial point : desired gap : final point
>>2:2:20 %TABLE OF 2
It will display.
2 4 6 8 …...20
It is typed in the beginning of a line in edit window. It create cell (highlighted
%%
rectangle) which can be executed separately / individually by using icon.
MATLAB MANUAL 4