Concept Flow - Relational expressions
Start with two values
Apply relational operator
Evaluate condition: true or false
Use result in program
End
Relational expressions compare two values and return true (1) or false (0) based on the condition.
a = 5; b = 3; c = a > b;
| Step | Expression | Evaluation | Result |
|---|---|---|---|
| 1 | a = 5 | Assign 5 to a | a = 5 |
| 2 | b = 3 | Assign 3 to b | b = 3 |
| 3 | a > b | Is 5 greater than 3? | true (1) |
| 4 | c = a > b | Store result of comparison in c | c = 1 |
| Variable | Start | After Step 1 | After Step 2 | After Step 4 |
|---|---|---|---|---|
| a | undefined | 5 | 5 | 5 |
| b | undefined | undefined | 3 | 3 |
| c | undefined | undefined | undefined | 1 |
Relational expressions compare two values using operators like >, <, ==. They return 1 (true) or 0 (false) in MATLAB. Example: c = a > b; Assigns 1 to c if a is greater than b, else 0. Used for decision making and conditions.