Introduction To The MATLAB
Introduction To The MATLAB
Introduction to the MATLAB
1- Introduction
MATLAB, which stands for MATrix LABoratory, is a technical computing environment
forhigh-performance numeric computation and visualization. Furthermore, MATLAB is a
modern programming language environment: it has sophisticated data structures, contains
built-in editing and debugging tools, and supports object-oriented programming. These factors
make MATLAB an excellent tool for teaching and research.
The basic building block in MATLAB is the matrix. The fundamental data type is the array.
Vectors, scalars, real and complex matrices are all automatically handled as special cases of
basic arrays. The built-in functions are optimized for vector operations. Thus, vectorized
commands or codes run much faster in MATLAB (vectorization is a way of computing in
which an operation is performed simultaneously on a list of numbers rather than sequentially on
each member of the list).
2- Starting MATLAB
1
MATLAB
AB ENGINEE
EERING // SSECOND YEAR//CHEM
YE EMICAL ENG
NG. DEPT.
-Thee Current D Directory::- MATLA AB file opperations use
u the currrent direcctory and the
t searchh path
as reeference ppoints. Anyy file you
u want to rrun must either be in the currrent direcctory or on
o the
searcch path.
A qu uick way tto view orr change the
t currennt directoryy is by ussing the Cu
Current Dirrectory fieeld in
the desktop
d tooolbar as shhown belo
ow.
For example
e U
Use on-linne help to request innfo on a sp
pecific fun
nction
>> help
h sqrt
-Thee Start buttton.
The MATLA AB Startt button providess easy access
a to tools, ddemos, shortcuts,
s and
docu
umentationn.
The MA
ATLAB deesktop on your com hich contaiins the proompt (>>) in the
mputer, wh
Com
mmand Winndow. Usuually, therre are 2 tyypes of pro
ompt:
>> fo
or full verrsion
EDU
U> for eduucational version
v
2
MATLAB
AB ENGINEE
EERING // S ECOND YEAR//CHEM
YE EMICAL ENG
NG. DEPT.
3
MATLAB
AB ENGINEE
EERING // SSECOND YEAR//CHEM
YE EMICAL ENG
NG. DEPT.
3- Qu
uitting MA
ATLAB
To end
e your M
MATLAB
B session, select Exxit MATL
LAB from the File m
menu in the
t desktoop, or
type quit in thee Commannd Windo
ow.
Main
n toolbar in Matlaab
3- Debug M
Menu:- thhis menu use
u to treaatment thee data.
4- Desktop
p Menu:- this menu use to coontrol the Main win
ndow of m
matlab programmingg
4
MATLAB
AB ENGINEE
EERING // SSECOND YEAR//CHEM
YE EMICAL ENG
NG. DEPT.
Usin
ng MATL
LAB as a calculator
c r
>> 1++2*3
ans =
7
MATLA
AB uses a default variable
v anns, short fo
or answer, to store tthe resultss of the cuurrent
calcu
ulation. N
Note that the
t variable ans is created (o
or overwritten, if itt is alread
dy existedd). To
avoid
d this, youu may assiign a value to a variiable or ou
utput argument nam
me. For exaample,
>> x = 1+2*3
x=
7
will result in x being giiven the value
v 1 + 2 £ 3 = 7.. This variiable nam
me can alw
ways be ussed to
referr to the ressults of thee previouss computaations. Theerefore, co
omputing 44x will ressult in
>> 4*x
4
ans =
28.0000
2
The followingg table givees the parttial list off arithmeticc operatorrs.
Operato
ors and Sp
pecial Characters
+ Pluss; additionn operator..
- Minnus; subtraaction operrator.
* Scallar and maatrix multiiplication operator.
.* Arraay multipllication op
perator.
^ Scallar and maatrix exponentiationn operator..
.^ Arraay exponeentiation operator.
\ Leftt-division operator.
/ Righht-divisionn operatorr.
.\ Arraay left-divvision operrator.
./ Arraay right-diivision operator.
5
MATLAB ENGINEERING // SECOND YEAR//CHEMICAL ENG. DEPT.
: Colon; generates regularly spaced elements and represents an entire row or
( ) l
Parentheses; encloses function arguments and array indices; overrides
[ ] Brackets; enclosures array elements.
. Decimal point.
… Ellipsis; line-continuation operator.
, Comma; separates statements and elements in a row.
; Semicolon; separates columns and suppresses display.
% Percent sign; designates a comment and specifies formatting.
_ Quote sign and transpose operator.
._ Nonconjugated transpose operator.
= Assignment (replacement) operator.
6