Professional Documents
Culture Documents
(CSC209)
Lecture (9)
Logical Statements and MATLAB
Operators
Dr.Omar Almutairi
Agenda
❖ Logical operators
statement
Top-Down Design Process
Large Task
Smaller
SubTask
SubTask SubTask
Smaller
SubTask
3
Build MATLAB script functions
The program design process
1. State problem
2. Define Inputs & Outputs
3. Design Algorithm of Steps
4. Turn Algorithm into MATLAB statements
5. Test
2-26
The program design process
Programming with MATLAB
6
True / False Operators
Relational
True 1
False 0
7
Examples
0 0 0 0 0 1
0 0 1 1 1 1
0 0 1 1 1 0
1 1 1 1 0 0
Examples
Assume that the following variables are initialized with
the values shown and calculate, the result of the
specified expressions:
value1 = 1
value2 = 0
value3 = 2
value4 = -10
value5 = 0
value6 = [1 2; 0 1]
The questions related to this example will be attached later
14
Examples
(a) ~value1
(b) ~value3
(c) value1 | value2
(d) value1 & value2
(e) value4 & value5
(f) ~(value4 & value5)
(g) value1 + value4
(h) value1 + (~value4)
(i) value3 && value6
(j) value3 & value6
15
Examples
1- value3>value1
2- value3>value1 && value1>value2
3- value3>value1 && value1>7
4- value3>value1 || value1>7
5- value3>value1 && value1>7 || 6>7
16
Selected MATLAB Logical function
17
Practice
18
END
19