MATLAB Conditional Statements

The following tutorial is an introduction to MATLAB conditional statements using the IF command and comparison statements such as those shown below.

 Operator
 <   - less than
 <=  - less than or equal to
 >   - greater than
 >=  - greater than or equal to
 ==  - equal
 ~=  - not equal to

Certain functions such as AND, OR, XOR, and NOT can be used to combine, select, or reverse the outcome of conditional statements. These logical operations change the results based on input data.

 Function
 if  - execute code with true logical condition
 and - return TRUE if both statements are TRUE (also &&)
 or  - return TRUE if either statement is TRUE (also ||)
 not - return the opposite of the input TRUE/FALSE (also ~)
 xor - exclusive OR is TRUE when both inputs differ

The following video tutorial demonstrates logical operations with a number guessing game.