{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Vectors - Boolean Indexing and Logical Vectors by Toshant

# Vectors - Boolean Indexing and Logical Vectors by Toshant -...

This preview shows pages 1–2. Sign up to view the full content.

Boolean Indexing For the following notes, please assume the follow lines of code to be true for the length of the notes. vec = [23 14 15 62] vec2 = [17 10] log_vec = [true false] log1_vec = [true false false true] log2_vec = [true true false false] log3_vec = [true true false true true] log4_vec = [1 0 1 0] 1. What is Boolean Indexing? a. Boolean Indexing is the process of indexing a vector with a logical vector. 2. What is a Logical Vector? a. A logical vector is a value of logical values. b. log_vec= [true true false false] b.i. The code above assigns log_vec to a logical vector. b.ii. Matlab will display this as [1 1 0 0]. c. log_vec2 = [1 1 0 0] c.i. The code above assigns the values [1 1 0 0]. These values are double, not logical. c.ii. Matlab will also display this as [1 1 0 0]. d. NOTE: In the two lines above, log_vec and lov_vec2 are not the same. One is a vector of logical values and one is a vector double values. Although Matlab will display the values as 0s and 1s, note that fundamentally, logical and double vectors are different, and therefore, they are assigned differently. 3. Creating a logical vector from other vectors. a. x = vec2 < 15 a.i. Here, Matlab will run a comparison between all of the values in vec2 and 15 and see if they are less than 15. If the value is less than 15, the corresponding logical value will be true, if the value is greater than 15, then the corresponding logical values will be false. a.ii. The first value of vec2 is 17. 17 is not less than 15, and therefore, the first value of the logical vector is false. The second value of vec2 is 10. This

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}