(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
Introduction to Matlab
1. Introduction To Matlab
Prepared by :
1
Prepared by:
Eng. Amr Ezz Eldin Rashed
Assistant lecturer
TAIF university,KSA
TEL:ksa 0554404723
2. Outlines(First Level) _24 hour
What is Matlab
Basic commands
Vectors and matrices
Statistics for vector and matrix
Control loops(if,for,switch,break)
2D plotting , mathematics(int ,diff ,limit,..)
Exam
2
3. Outlines(Second Level)_24hour
3D plotting, animation
Dialog box
Simulink
Graphical user interface
Image and sound processing
البرامج الجاهزة
Project
EXAM
3
4. Outlines(Third Level)_24 hour
Introduction to Image Processing
Point Processing ,Spatial Filtering
Neighborhood Processing
The Fourier Transform
Image Restoration
Image Segmentation
project
4
5. What is Matlab?
What is possible in Matlab? graphic examples
How Matlab works? matrix, vector & scalar
syntax & important operators
basic commands & plot commands
creating a m-file
Statistics in Matlab some basics & example
Algebraic operations in Matlab
Useful links & other tutorials
5
Introduction to MATLAB
6. What is MATLAB
The name MATLAB stands for Matrix laboratory(or mathematical laboratory).
MATLAB is an interactive system whose basic data element is an array that does not require dimensioning.
It‟s both a computer programming language, and a software environment for using that language effectively.
Typical
6
7. What is MATLAB
Matlab is a commercial "Matrix Laboratory" package which operates as an interactive programming environment.
Matlab is available for PC's, Macintosh and UNIX systems.
Matlab is well adapted to numerical experiments.
Matlab program and script files (m-files) always have filenames ending with ".m";
The programming language is exceptionally straightforward since almost every data object is assumed to be an array.
Graphical output (figure) is available to supplement numerical results.
Online help is available from the Matlab prompt (a double arrow) by typing help
7
8. Typical Uses
Math and computation Algorithm development Modeling, simulation, and prototyping Data analysis, exploration, and visualization Scientific and engineering graphics Application development including GUI
8
9. Why use Matlab?
Advantages:
Handles vector and matrices very nice
Quick plotting and analysis
EXTENSIVE documentation (type „help‟)
Lots of nice functions: FFT, fuzzy logic, neural nets, numerical integration, OpenGL (!?)
Drawbacks:
Slow compared to C or Java
9
10. Matlab History
In the 1970‟s, Cleve Moler “Professor of Math & Computer Science, Chief Author of MatLab and one of the Founders of Mathworks.Inc” participated in developing (EISPACK) and (LINPACK). Those were collection of Fortran subroutines for solving linear equations and Eigen value problems.
Later, when teaching courses in mathematics, Moler wanted his students to be able to use LINPACK and EISPACK without requiring knowledge of Fortran, so he developed the first MATLAB in 1977 as an interactive system to access LINPACK and EISPACK.
10
11. MatLab History
The first Matlab was written in 2000 lines of Fortran, with Matrices as the only data type, 80 functions, no .m files and no toolboxes.
Jack Little, one of Moler‟s students saw Matlab potentials in Control systems & Signal Processing. They founded together Mathworks, Inc. in 1980
Mathworks is now responsible for development, sale, and support for MATLAB
MATLAB was rewritten in C with more functionality (such as plotting routines), and now it contains more than 80,000 functions.
11
12. The Basic Matlab System
It consists of 5 main parts:
–Development Environment.
–MATLAB Mathematical Function Library.
–MATLAB Language.
–Graphics.
–MATLAB External Interfaces
And finally the MatLab Toolboxes
–Toolboxes are comprehensive collections of MATLAB functions (M- files) that extend the MATLAB environment to solve particular classes of problems.
–Areas in which toolboxes are available include signal processing, control systems, neural networks, communications, wavelets, Data Acquisition, simulation, and many others.
12
15. Development Environment
15
Command Window
History
Work Space
Variables stores here
All of ur previous commands stores here
All commands, programs runs from here
16. Variables
MATLAB variable names must begin with a letter, which may be followed by any combination of letters, digits, and underscores. MATLAB distinguishes between uppercase and lowercase characters, so A and a are not the same variable(case sensitive). When naming a variable, make sure you are not using a name that is already used as a function name,begin with character .
17. Special Values
Function
description
Ans
Most recent answer (variable). If you do not assign an output variable to an expression, MATLAB automatically stores the result in ans.
pi
3.1415926535897...
inf
Infinity. Calculations like n/0, where n is any nonzero real value, result in inf.
I,J
The imaginary unit √-1
NaN,nan
Not-a-Number, an invalid numeric value. Expressions like 0/0 and inf/inf result in a NaN, as do arithmetic operations involving a NaN. n/0, where n is complex, also returns NaN.
18. Special Values
Description
Function
Beep sound
beep
Maximum real number that can be used
realmax
minimum real number that can be used
realmin
Specifies the accuracy of floating point
Precision .
الخطوة ب نٌ عدد نٌ أو أصغر عدد مٌكن تعر فٌه
eps
18
19. Operators
Arithmetic
–numeric computations, e.g., 2^10 Relational
–quantitative comparison of operands
–e.g., a < b Logical
–AND, OR, NOT
–return Boolean variable, 1 (TRUE) or 0 (FALSE)
20. Arithmetic operators
example
symbol
Operation
3+22
+
Addition
54.6-16.5
_
subtraction
3.14*6
*
Multiplication
10/100
10010
/ or
Division
2^8
^
power
20
21. Relational Operators
Description
Relational Operator
Less than
<
Less than or equal
<=
Greater than
>
Greater than or equal
>=
Equal to
==
Not equal to
~=
21
23. Logical Operators
Logical Operator
Description
&
Element by element AND
|
Element by element OR
~
NOT
&&
Scalar AND with short circuiting
||
Scalar OR with short circuiting
26. Complex functions
Description
Item
Define a complex number
Complex(2,-3)
Absolute value ;|x|
Abs(x)
Angle of complex number x
Angle(x)
Complex conjugate of x
Conj(x)
Imaginary part of a complex number x
Imag(x)
Real part of complex number x
Real(x)
26
28. Relational and Logical Functions
Function
Description
xor(x,y)
Exclusive OR
any(x)
True if any element is non zero
all(x)
True if all elements are non zero
Isequal(x,y)
True if arrays are numerically equal
Isfloatpt
True for a floating point number
isprime
True for a prime number
34. System and file commands
Description
Item
Clears command window
clc
Remove variables from memory
Clear , clear all
Display documentation
doc
Checks for existence of file or variable
exist
Declares variables to be global
global
Display help text in the command window
Help
Display help text in the help browser
helpwin
Searches help entries for a keyword
lookfor
Stops Matlab
Quit or exit
List current variables
who
Long display) ) List current variables
whos
34
39. Mathematical functions
item
Description
factor
التحل لٌ ال العوامل الاول ةٌ
Primes وٌلد قائمة بالاعداد الاول ةٌ الاقل من
x
isprime عٌ دٌ
true اذا كان العدد اول اٌ
Gcd القاسم المشترك الاكبر
lcm ا جٌاد المضاعف المشترك الاصغر
Factorial(x) لا جٌاد المضروب
Gamma(x) تابع جاما
Beta(x,y) تابع ب تٌا
39
42. System and file Commands
item
Description
cd
Change current directory
Date
Display current date
dir
Lists all files in the current directory
mkdir
Used to make new directory
pwd
Present work directory
what
Lists all matlab files
Clock
Display current clock and date
42
76. برنامج لحساب زاو ةٌ خط
X=[1 0 0;0 1 0;0 0 1]; [I,j]=find(x==1); Length=max(i)-min(i); Width=max(j)-min(j); Ang=atand(length/width);
76
77. Determines matrix elements
d=[ 1 2;4 5; 3 2] d = 1 2 4 5 3 2 >> d(1,:) %row 1 and all columns ans = 1 2 >> d(1,2) % row 1 and all column 2 ans = 2 >> d(:,2) %all row and l column 2 ans = 2 5 2
87. Unique,intersect,setdiff
87
لحذف ما هو مكرر
وترت بٌ النت جٌة
الحصول عل العناصر
المشتركة ب نٌ مصفوفت نٌ
الحصول عل العناصر
الموجودة ف 1 وغ رٌ
موجودة ف 2
100. Approximation functions
Floor : rounds value towards negative infinity Ceil: rounds value towards positive infinity Fix: rounds value towards zero Round: normal approximation
100
126. Reading and writing sound
>>[y,fs]=wavread('C:WINDOWSMediachimes.wav');
>>Help auread
>> soundsc(y) or wavplay(y,fs)
>>size(y)
>>wavwrite(y,‟c:aa.wav‟) or auwrite
>>نأخذ جزء من الصوت ونتعامل معه
126
130. Flow Control
MATLAB has several flow control constructs:
For loop.
If statement.
Switch and case.
While.
Continue.
Break.
Try – catch.
Return.
131. For Loop
for x = array
(commands)
end The (commands) are executed once for every column in array At each iteration, x is assigned to the next column of the array
144. Example
What is your name? How old are you? طٌبع age, name
144
145. Example
Nam=input („what is your name?‟ , ‟s‟);
character حٌتوي على string
Age=input („how old are you?‟);
Disp(nam)
Disp(age)
145
146. Note
ملحوظة:
لك تٌرك سطر نستخدم علامة
ولك طٌبع backslash نستخدم علامة
ولطبع name ,age بجانب بعضهم
Disp ([x, y]);
إما أن كٌون ⤾ x, y
أي جٌب أن كٌونا من نفس النوع String or num
Disp ([nam, num2str (age)]);
146
147. Example
اطبع مجموع الأعداد التى تقبل القسمة على 5
sum=0;
For i=0:5:100
sum=sum+I;
end
Disp(sum)
147
148. Nested Loops
for n=1:5
for m=5:-1:1
A(n,m)=n^2+m^2;
end
end
A =
2 5 10 17 26
5 8 13 20 29
10 13 18 25 34
17 20 25 32 41
26 29 34 41 50
150. While Loops
while expression
(commands)
end Commands are executed as long as all elements in expression are true. Usually evaluation of expression gives scalar
–In case of array all elements must be true
151. Example
while x<=15
x=2*x;
end
Be careful and try to avoid infinite loops!
To stop the execution of an infinite loop use Ctrl+C
x =3
x =24
152. If-End Structure
if expression
(commands)
end The (commands) are evaluated if all elements in expression are true (nonzero)
153. If-Else-End Structure
if (expression)
(commands evaluated if true)
else
(commands evaluated if false)
end
154. Flow control - selection
The if-elseif-else construction
if <logical expression> <commands> elseif <logical expression> <commands> else <commands> end
if height>170
disp(’tall’)
elseif height<150
disp(’small’)
else
disp(’average’)
end
155. Example
X=input ('enter any value'); If (x>0) disp ('positive'); End IF (x<0) disp ('negative'); End لا غٌلق برنامج ال matlab ب end
155
156. Example
iF (x>0) disp ('positive'); else if (x<0) disp ('negative'); else disp ('zero'); End ملحوظة : وٌجد دالة جاهزة تقوم بنفس الوظ فٌة
sign
156
157. Example
أدخل ق مٌة x,y
ونحدد هل x اكبر من y ام لا ونطبع x,y
X is greater than y X is lower than y X is equal to y
157
159. Example
لطباعة الأعداد التى لا تقبل القسمة على 5
For i=0:100 If (rem(I,5)~=0) disp(i); End End
159
160. برنامج لا جٌاد جذور معادلة ترب عٌ ةٌ
Disp.→this program is used to solve the quadratic eqn Disp→ Ax2+Bx+c=0 a=input→enter the value of A:___ b=input→enter the value of B:___ c=input→ enter the value of C:___ D=B2- 4AC
•X1=x2=-b/2a X1= (-B+sqrt (d))/ (2*a))
X2= (-B-sqrt (d) )/ (2*a))
160
0
Non zero
162. Example
X=floor (rand*6) +1; If (x==1) disp ('that is 1'); Else if (x==2) disp ('that is 2'); Else if (x==3) disp ('that is 3'); Else if (x==4) disp ('that is 4'); Else if (x==5) disp ('that is 5'); Else disp ('that is 6'); Or else if (x==6) disp ('that is 6'); end
162
165. Switch-Case Construction
switch expression
case test_expression1
(commands1)
case {test_expression2, test_expression3}
(commands2)
otherwise
(commands 3)
end
166. Example
method = 'Bilinear';
switch (method)
case 'linear'
disp('Method is linear')
case 'cubic'
disp('Method is cubic')
otherwise
disp('Unknown method.')
end
Method is Unknown method
167. باستخدام switch فى حالة multiple cases
X=floor (rand*6)+1; Switch x → expression or variable مٌكن أن كٌون
Case 1 Disp ('that is 1'); Case 2 Disp ('that is 2'); Case 3 Disp ('that is 3'); Case 4 Disp ('that is 4'); Case 5 Disp ('that is 5'); Case 6 Disp ('that is 6'); Or Otherwise Disp ('that is 6'); End
167
169. Example
لحساب أكثر من حالة مع بعض
X=floor (rand*6)+1; 1-if (x==1 | x==2 | x==3) 2-if (1<=x<=3) 3-case {1,2,3} disp ('from 1 to 3') case {4,5} disp ('4 or 5') case 6 / otherwise disp (that is 6'); end
169
240. Code
% --- Executes on button press in put. function put_Callback(hObject, eventdata, handles) % hObject handle to put (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) distor=200; set(handles.edit1,'String',distor);
240