0% found this document useful (0 votes)
10 views16 pages

Logical Functions & If Statement

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views16 pages

Logical Functions & If Statement

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

PROGRAMMING WITH MATLAB

LOGICAL FUNCTIONS
CONDITIONAL STATEMENTS

Bushra Fatima
NED University of Engineering & Technology June 29, 2020
OUTLINE
1. LOGICAL FUNCTIONS

2. CONDITIONAL STATEMENTS
1. if – end STRUCTURE
2. if – else - end STRUCTURE
3. if – elseif – else - end STRUCTURE

Textbook: A. Gilat, Matlab: An Introduction with Applications 4th Edition. John Wiley &
Sons, Incorporated, 2016. (Chapter 6: Programming with MATLAB)
PROGRAMMING WITH MATLAB BUSHRA FATIMA
LOGICAL FUNCTIONS | IF-END | IF-ELSE-END | IF-ELSEIF-ELSE-END 3 of 16

Built-in Logical Functions (and, or, not)


MATLAB has built-in functions that are
equivalent to the logical operators:

1. and(A,B) = A&B

2. or(A,B)=A|B

3. not(A)=~A

METU NCC
PROGRAMMING WITH MATLAB BUSHRA FATIMA
LOGICAL FUNCTIONS | IF-END | IF-ELSE-END | IF-ELSEIF-ELSE-END 4 of 16

Other built-in Logical Functions (1)

METU NCC
PROGRAMMING WITH MATLAB BUSHRA FATIMA
LOGICAL FUNCTIONS | IF-END | IF-ELSE-END | IF-ELSEIF-ELSE-END 5 of 16

Other built-in Logical Functions (2)

METU NCC
PROGRAMMING WITH MATLAB BUSHRA FATIMA
LOGICAL FUNCTIONS | IF-END | IF-ELSE-END | IF-ELSEIF-ELSE-END 6 of 16

Truth Table

METU NCC
PROGRAMMING WITH MATLAB BUSHRA FATIMA
LOGICAL FUNCTIONS | IF-END | IF-ELSE-END | IF-ELSEIF-ELSE-END 7 of 16

CONDITIONAL STATEMENT

• Decision-making command:
• execute the command
• or to skip the command

• In a conditional statement, a conditional expression is


stated.

• True (1), a group of commands that follow the


statement are executed.

• False (0), the computer skips the group.

METU NCC
PROGRAMMING WITH MATLAB BUSHRA FATIMA
LOGICAL FUNCTIONS | IF-END | IF-ELSE-END | IF-ELSEIF-ELSE-END 8 of 16

If-end statement flowchart

METU NCC
PROGRAMMING WITH MATLAB BUSHRA FATIMA
LOGICAL FUNCTIONS | IF-END | IF-ELSE-END | IF-ELSEIF-ELSE-END 9 of 16

If-end statement

METU NCC
PROGRAMMING WITH MATLAB BUSHRA FATIMA
LOGICAL FUNCTIONS | IF-END | IF-ELSE-END | IF-ELSEIF-ELSE-END 10 of 16

If-else-end statement flowchart

METU NCC
PROGRAMMING WITH MATLAB BUSHRA FATIMA
LOGICAL FUNCTIONS | IF-END | IF-ELSE-END | IF-ELSEIF-ELSE-END 11 of 16

If-else-end statement

METU NCC
PROGRAMMING WITH MATLAB BUSHRA FATIMA
LOGICAL FUNCTIONS | IF-END | IF-ELSE-END | IF-ELSEIF-ELSE-END 12 of 16

If-elseif-else-end statement flowchart

METU NCC
PROGRAMMING WITH MATLAB BUSHRA FATIMA
LOGICAL FUNCTIONS | IF-END | IF-ELSE-END | IF-ELSEIF-ELSE-END 13 of 16

If elseif  else  end

METU NCC
PROGRAMMING WITH MATLAB BUSHRA FATIMA
LOGICAL FUNCTIONS | IF-END | IF-ELSE-END | IF-ELSEIF-ELSE-END 14 of 16

If elseif elseif  end

METU NCC
PROGRAMMING WITH MATLAB BUSHRA FATIMA
LOGICAL FUNCTIONS | IF-END | IF-ELSE-END | IF-ELSEIF-ELSE-END 15 of 16

Exercise

METU NCC
PROGRAMMING WITH MATLAB BUSHRA FATIMA
LOGICAL FUNCTIONS | IF-END | IF-ELSE-END | IF-ELSEIF-ELSE-END 16 of 16

Exercise

METU NCC

You might also like