Lecture7

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

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

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

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

View Full Document
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
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”

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

View Full Document
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
Note – value and class

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

View Full Document
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
Notes: Can compute using the result: e.g. “how many of a

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.

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
Ask a homework question - tutors are online