Matlab - logical operators Flashcards

1
Q

what are these signs?
>
<
==
~=

A

Greater than
Less than
Is equal to
Is not equal to

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

what are these signs in Matlab?
& | ~

A

they are logical AND, OR and NOT

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

when you use just logical operators what do you get in return?

A

an index array consisting of 1s and 0s

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

what would the output be?
» A = [1 5 3 4 8 3];
» B = A>2

A

B = 0 1 1 1 1 1 (0 is false, 1 is true)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

what would the output be for this?&raquo_space;
» A = [1 5 3 4 8 3];
C = A<5

A

C = 1 0 1 1 0 1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

if
» A = [1 5 3 4 8 3];
» B = A>2
B = 0 1 1 1 1 1
C = A<5
C = 1 0 1 1 0 1

what is D = B & C

A

D = 0 0 1 1 0 1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

how would you logically index D into A? what would be the output?

> > A = [1 5 3 4 8 3];
B = A>2
B = 0 1 1 1 1 1
C = A<5
C = 1 0 1 1 0 1
D = B & C
D = 0 0 1 1 0 1

A

E = A(D)
E = 3 4 3

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

You can convert a logical index into a subscript index
using find, which tells you the non-zeros values of the logical.

A

F = find(D)
F = 3 4 6

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

you can use logical indexing when one variable is used to categorise another
example:
data = [4 14 6 11 3 14 8 17 17 12 10 18];
cat = [1 3 2 1 2 2 3 1 3 2 3 1];

how would you find where cat is 2? and their corresponding values?

A

> > cat2 = cat==2
cat2 = 0 0 1 0 1 1 0 0 0 1 0 0
data2 = data(cat2);
data2 = 6 3 14 12

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

how would you find the mean for the category 2 data?

A

mdat2 = mean(data2)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly