Matlab Relational & Logical Operations Quiz

Matlab
0 Passed
0% acceptance

40 questions on MATLAB's comparison and logical operators, covering equality, inequality, boolean logic, and common pitfalls.

40 Questions
~80 minutes
1

Question 1

Which operator checks if two values are equal?

A
==
B
=
C
===
D
eq
2

Question 2

What is the result of `5 > 3`?

A
logical 1 (true)
B
logical 0 (false)
C
5
D
Error
3

Question 3

Which operator means 'not equal to'?

A
~=
B
!=
C
<>
D
!==
4

Question 4

What is the primary difference between `=` and `==`?

A
`=` assigns a value; `==` compares values
B
`==` assigns a value; `=` compares values
C
They are interchangeable
D
`=` is for numbers; `==` is for strings
5

Question 5

Which symbol represents the logical AND operator (element-wise)?

A
&
B
&&
C
and
D
+
6

Question 6

What is the result of `true | false`?

A
logical 1
B
logical 0
C
NaN
D
Error
7

Question 7

What does the expression `~(5 > 10)` evaluate to?

A
logical 1
B
logical 0
C
-1
D
Error
8

Question 8

If `A = [1 0 1]` and `B = [0 1 1]`, what is `A & B`?

A
[0 0 1]
B
[1 1 1]
C
[1 0 0]
D
[0 1 0]
9

Question 9

Which operator represents 'greater than or equal to'?

A
>=
B
=>
C
D
ge
10

Question 10

What is the data type of the result of a relational operation?

A
logical
B
double
C
char
D
integer
11

Question 11

What is the result of `NaN == NaN`?

A
logical 0 (false)
B
logical 1 (true)
C
NaN
D
Error
12

Question 12

Which function returns true if *any* element in a vector is non-zero (true)?

A
any(v)
B
all(v)
C
some(v)
D
exists(v)
13

Question 13

What does `3 < 5 < 4` evaluate to in MATLAB?

A
logical 1 (true)
B
logical 0 (false)
C
Error
D
It depends on x
14

Question 14

Which operator is the 'Short-Circuit AND'?

A
&&
B
&
C
and
D
short(and)
15

Question 15

How do you check if two arrays `A` and `B` are identical in size and content?

A
isequal(A, B)
B
A == B
C
A = B
D
same(A, B)
16

Question 16

What is the result of `xor(true, true)`?

A
logical 0
B
logical 1
C
2
D
Error
17

Question 17

Which function checks if a value is infinite?

A
isinf(x)
B
isnan(x)
C
infinite(x)
D
checkinf(x)
18

Question 18

If `v = [10 20 30]`, what does `v > 15` return?

A
[0 1 1]
B
[10 20 30]
C
[20 30]
D
logical 1
19

Question 19

How do you convert a numeric array `A` to logicals (0 becomes false, non-zero becomes true)?

A
logical(A)
B
bool(A)
C
boolean(A)
D
toLogical(A)
20

Question 20

What is the correct way to check if `x` is between 1 and 10 (inclusive)?

A
x >= 1 & x <= 10
B
1 <= x <= 10
C
x >= 1 and x <= 10
D
between(x, 1, 10)
21

Question 21

What does `~[0 1 0]` result in?

A
[1 0 1]
B
[0 1 0]
C
[-1 0 -1]
D
Error
22

Question 22

Which operator has the highest precedence?

A
Arithmetic (e.g., + *)
B
Relational (e.g., > <)
C
Logical AND (&)
D
Logical OR (|)
23

Question 23

What is the result of `strcmp('apple', 'apple')`?

A
logical 1
B
logical 0
C
[1 1 1 1 1]
D
True
24

Question 24

Why is comparing floating point numbers with `==` dangerous (e.g., `0.1 + 0.2 == 0.3`)?

A
Floating point precision errors can make them slightly different
B
MATLAB cannot compare floats
C
It causes a syntax error
D
It rounds them to integers first
25

Question 25

What does `all([1 1 0])` return?

A
logical 0
B
logical 1
C
2
D
NaN
26

Question 26

Which keyword represents the logical value 'true'?

A
true
B
True
C
TRUE
D
t
27

Question 27

What is the result of `1 | 0 & 0`?

A
1
B
0
C
Error
D
NaN
28

Question 28

How do you find the indices of all elements in `v` that are greater than 5?

A
find(v > 5)
B
index(v > 5)
C
search(v > 5)
D
where(v > 5)
29

Question 29

What happens if you use `&&` on arrays (e.g., `[1 0] && [0 1]`)?

A
Error
B
[0 0]
C
0
D
1
30

Question 30

What is the logical negation of `x > 5`?

A
x <= 5
B
x < 5
C
x >= 5
D
x == 5
31

Question 31

Which function allows you to compare two strings case-insensitively?

A
strcmpi
B
strcmp
C
strequal
D
ignorecase
32

Question 32

What is the result of `logical(5)`?

A
logical 1
B
logical 5
C
Error
D
logical 0
33

Question 33

If `A` is a logical array, how do you convert it back to 1s and 0s of type double?

A
double(A)
B
num(A)
C
int(A)
D
value(A)
34

Question 34

What does `isempty([])` return?

A
logical 1
B
logical 0
C
Error
D
NaN
35

Question 35

Can you use logical arrays to index into other arrays?

A
Yes, it extracts elements where the logical index is true
B
No, indices must be integers
C
Only if they are the same size
D
Yes, but it returns 0s
36

Question 36

What is the result of `false < true`?

A
logical 1
B
logical 0
C
Error
D
NaN
37

Question 37

Which operator is used for 'Element-wise OR'?

A
|
B
||
C
or
D
/
38

Question 38

What does `bitand(5, 3)` do?

A
Performs bitwise AND on the binary representations
B
Performs logical AND
C
Adds the numbers
D
Checks if both are non-zero
39

Question 39

If `x = 5`, what is `x ~= 5`?

A
logical 0
B
logical 1
C
Error
D
NaN
40

Question 40

What is the result of `any([0 0 0])`?

A
logical 0
B
logical 1
C
NaN
D
Error

QUIZZES IN Matlab