Logical Vectors - PowerPoint PPT Presentation

1 / 8
About This Presentation
Title:

Logical Vectors

Description:

Using Logical Operators. Draw the sine curve from -270 to 270 degree with only the positive part ... Draw the tangent curve from -270 to 270 degree ... – PowerPoint PPT presentation

Number of Views:18
Avg rating:3.0/5.0
Slides: 9
Provided by: saikatmuk
Category:
Tags: curve | logical | vectors

less

Transcript and Presenter's Notes

Title: Logical Vectors


1
Logical Vectors
2
Using Logical Operators
  • Draw the sine curve from -270 to 270 degree with
    only the positive part
  • Draw the plot for sin(x)/x from -270 to 270
    degrees
  • Draw the tangent curve from -270 to 270 degree
  • In a random number generator from 0 to 10, how
    many numbers would be gt 5 on average
  • What is the chance of getting six after rolling
    a well balanced die

3
Precedence of Operators
  • ()
  • (unary) -(unray)
  • /
  • (binary) -(binary)
  • gt lt gt lt

4
Precedence of Operators
  • What will be the output
  • 3gt 1 0
  • 1 lt rlt 5
  • a gt b
  • a gt b
  • (a gt b)

5
Logical Vectors
  • We learnt that indices of vectors can be
    subscripted
  • a-2 0 1 5 9 a(5 1 3)
  • We can use logical vectors to obtain values at
    indices
  • a(logical( 0 1 0 1 0)
  • Remove all elements in a are that are greater
    than zero

6
Logical Functions
  • islogical
  • Returns 1 if it is a logical vector
  • any
  • Returns 1 if any element of a is non-zero
  • all
  • Returns 1 if all elements of a are non-zero
  • exist
  • Returns 1 is a is a vraibel defined in
    workspace
  • find
  • Returns a vector with indices that match given
    condition
  • isempty
  • Returns 1 if array a is empty

7
Using Logical Functions
  • Given the temperatures of the week in an array,
  • Find which day was the hottest
  • Check if there was a day when the temperature was
    below 0 degree celcius
  • Was there any day where the temperature was below
    -10 degree celcius
  • Logical vectors and functions make shorter codes

8
Summary
  • What we learned
  • Sections covered
  • All of chapter 5
Write a Comment
User Comments (0)
About PowerShow.com