CEE 15 Introduction to Computing for Civil Engineers
24
Chapter 3 Branching Statements
3.1. Relational Operators
MATLAB has six
relational operators
for comparing two matrices of equal size or two scalars.
Table 3.1 Relational operators
Relational Operator
Interpretation
<
Less than
<=
Less than or equal to
>
Greater than
>=
Greater than or equal to
==
Equal to
~=
Not equal to
Consider the following program:
a = input('a =');
b = input('b =');
if a > b
disp('a is greater than b')
end
if a < b
disp('a is greater than b')
end
if a == b
disp('a is equal to b')
end
Output 1:
a =3
b =4
b is greater than a
Output 2:
a =4
b =2
a is greater than b
Output 3:
a =5
b =5
a is equal to b
Output 4:
a =[2 3 5]
b =[3 7 9]
b is greater than a
Output 5:
a = [2 4 5]
b = [1 3 6]

This ** preview** has intentionally

**sections.**

*blurred***to view the full version.**

*Sign up*