# Lecture34 - Lecture 34 More Programming in MATLAB...

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

Engineering 101 Engineering 101 Lecture 34 Lecture 34 More Programming in MATLAB More Programming in MATLAB Prof. Michael Falk University of Michigan, College of Engineering

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

View Full Document
Announcements Announcements Project 8 – Due Weds Dec 6 at 9pm Paper copies and written part due in section on Dec 7 and 8 Projects 5 and 6 will be returned Tues/Weds in lab sections. Exam 3 will be returned on Thurs/Fri in lab sections (some sections may be delayed). Gradebook will be reposted by the end of the week. My office hours today will be 1:30-2:30 in CSE 2636 rather than immediately after class.
Announcements Announcements SWE Majors Fair Tomorrow, 7:30-8:30 in Dow 1013 The Majors Fair will be a very informal event with tables throughout the room for each major within engineering. I will have at least one senior (or junior) from each major at their major's table. I am inviting all engineering first and second year students to come talk to the upperclassmen about any majors that they are interested in - what the major really is about, what kind of jobs you can get with it, classes to take, etc. I especially hope that this event will help undecided students make informed decisions about choosing a major.” Lisa Winkel

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

View Full Document
The If Construct in MATLAB The If Construct in MATLAB The basic form of the if construct in MATLAB is: if control_exp1 statement1 statement2 etc. elseif control_exp2 statement 3 statement 4 etc. else statement 5 statement 6 end Every construct must have an if and an end. The other parts are optional. You can have multiple elseif clauses.
Example of the If Construct Example of the If Construct x = input(‘Enter a number’); if x > 0 disp(‘The number is positive’); elseif x < 0 disp(‘The number is negative’); else disp(‘The number is zero’); end

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

View Full Document
Nested If Constructs Nested If Constructs You can nest if constructs much as you could in C++ if ( pos(x+1, y) == 0) if lastmovex ~= -1 x=x+1; lastmovex = 1; end elseif (pos(x-1, y) == 0) if lastmovex ~= 1; x=x-1; lastmovex = -1; end end
The Switch Construct MATLAB also has a switch construct for cases in which you are choosing from a number of alternatives: switch (switch_expr) case case_expr_1 Statement 1 Statement 2 case case_expr_2 Statement 3 Statement 4 otherwise Statement 5 end After executing the particular case the code jumps to after the end. The otherwise part is

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 ]}

### Page1 / 44

Lecture34 - Lecture 34 More Programming in MATLAB...

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

View Full Document
Ask a homework question - tutors are online