MATLAB Relational Operators

🔍 MATLAB Relational Operators
The result of a relational operation is always logical: true (1) or false (0).
MATLAB is developed by MathWorks.
🔹 List of MATLAB Relational Operators
| Operator | Meaning |
|---|---|
> | Greater than |
< | Less than |
>= | Greater than or equal to |
<= | Less than or equal to |
== | Equal to |
~= | Not equal to |
🧪 Examples with Output
1️⃣ Greater Than (>)
Output
2️⃣ Less Than (<)
Output
3️⃣ Greater Than or Equal (>=)
Output
4️⃣ Less Than or Equal (<=)
Output
5️⃣ Equal To (==)
Output
⚠️ Use == for comparison, not = (assignment).
6️⃣ Not Equal To (~=)
Output
📊 Relational Operators with Arrays (Element-wise)
Output
📌 Each element is compared individually.
🔗 Using Relational Operators in if Statement
Output
🔁 Combining Relational & Logical Operators
Output
⚠️ Important Notes
Output is always logical
Works on scalars, vectors, and matrices
For arrays, operations are element-wise
Commonly used in conditions and loops
🎯 Interview Questions:
🔹 Q1. What is the output type of relational operators in MATLAB?
Answer: Logical (true or false).
🔹 Q2. Difference between = and ==?
Answer:= assigns a value, == compares two values.
🔹 Q3. Which operator is used for “not equal to”?
Answer: ~=
🔹 Q4. Can relational operators work on arrays?
Answer: Yes, element-wise comparison is performed.
🔹 Q5. What is the result of 5 > 10?
Answer: false (logical 0).
🔹 Q6. Where are relational operators mostly used?
Answer: In if, while, for loops, and decision making.
🔹 Q7. What does >= mean?
Answer: Greater than or equal to.
✅ Summary
Relational operators compare values
Result is always logical
Works with scalars & arrays
Essential for control statements
