Lecture7 - EGR 106 Lecture 7 Relational Logical Conditional...

Info iconThis preview shows pages 1–8. Sign up to view the full content.

View Full Document Right Arrow Icon
EGR 106 Lecture 7 Relational, Logical, Conditional, if-else-end So far, we’ve looked at simple programming via “ scripts ” = programs of sequentially evaluated commands Today, extend features to: additional operators branches to control operations Textbook: 6.1 – 6.2
Background image of page 1

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

View Full DocumentRight Arrow Icon
Relational Operators – the Idea In formal English someone might ask you “Is your age greater than or equal to 21?” Answers could include: Yes, of course Here’s my ID card I’m 18 I knew this would happen if I forgot my ID No
Background image of page 2
Using mathematical notation, we test or compute the relation age ≥ 21 (or written in MATLAB) age >= 21 And expect 1 of only 2 answers: “Yes” or “True” “No” or “False”
Background image of page 3

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

View Full DocumentRight Arrow Icon
Relational Operators in MATLAB A operator B A and B can be: Variables or constants or expressions to compute Scalars or arrays (match the sizes on arrays!) Numeric or string Operators: > > = = = < < = ~ = Result is true (1) or false (0) – perhaps an array
Background image of page 4
Note – value and class
Background image of page 5

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

View Full DocumentRight Arrow Icon
More Examples: expression result 5 < 7 1 [ 3, 5, 2 ] > = [ 1, 0, 12 ] 1 1 0 max( 1:6 ) < = 7 1 [3, pi, -12 ] > 1 1 1 0 'Tom' = = 'Bob' 0 1 0 'Tom' = = 'm' 0 0 1
Background image of page 6
Notes: Can compute using the result: e.g. “how many of a
Background image of page 7

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

View Full DocumentRight Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 10/03/2011 for the course EGR 106 taught by Professor Taggart during the Spring '09 term at Rhode Island.

Page1 / 29

Lecture7 - EGR 106 Lecture 7 Relational Logical Conditional...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online