Logical Indexing Flashcards

1
Q

Use logical indexing to select values greater than 2 in the array below

Data = [1 3 0 8 2 7 1]

A

Data(data > 2)

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

What can happen if logical indexing is used on a matrix?

Eg : matrix = [10 20 30; 1 2 3]
Select values >= 10

How to overcome this problem

A

When logical indexing is used on a matrix, possible that matrix size change due to loss of values

Eg: matrix becomes a [1x3] array

When doing logical indexing, tell MATLAB to fill empty spaces with 0

Matrix(matrix >= 10) = 0

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

How to use logical indexing to select data in an array

A

Logical indexing can be used to select data from another variable when the position where data is needed has a corresponding 1 value from the logical index

Eg: index = [1 1 0 1] , data = [3 9 6 7]
Data(index) = [3 9 7]

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