Conditional Statements ENGR 1187 MATLAB 7. Conditional Statements in Real Life A Fluorescence Activated Cell Sorter (FACS) sorts cells based on predetermined.

Slides:



Advertisements
Similar presentations
Decision Structures - If / Else If / Else. Decisions Often we need to make decisions based on information that we receive. Often we need to make decisions.
Advertisements

MATLAB Conditional Statements ENGR 1181 Presentation by Annie Abell.
2D Plots 1 ENGR 1181 MATLAB 12.
Week 6 - Programming I So far, we’ve looked at simple programming via “scripts” = programs of sequentially evaluated commands Today, extend features to:
Input and Output ENGR 1181 MATLAB 5. Input and Output In The Real World Script files (which provide outputs given inputs) are important tools in MATLAB.
Program Design ENGR 1181 MATLAB 11. MATLAB Program Design in Real Life Complex manufacturing processes require careful logic mapping to determine what.
Fall 2004ENGR 111A MatLab – Palm Chapter 4, Part 2 The if and switch structure Class 10.1 Sections: 4.4 and 4.6.
Example – calculating interest until the amount doubles using a for loop: will calculate up to 1000 years, if necessary if condition decides when to terminate.
MATLAB Loops and Branching.
Week 6 - Programming I So far, we’ve looked at simple programming via “scripts” = programs of sequentially evaluated commands Today, extend features to:
Precedence Parentheses Arithemetic ^ * / + - (exception logical not ~ ) Relational > =
Week 7 - Programming I Relational Operators A > B Logical Operators A | B For Loops for n = 1:10 –commands end.
Lecture 13 Decision structures
General Computer Science for Engineers CISC 106 Lecture 05 Dr. John Cavazos Computer and Information Sciences 2/20/2009.
Precedence Parentheses Arithemetic ^ * / + - (exception logical not ~ ) Relational > =
Week 7 - Programming II Today – more features: – Loop control – Extending if/else – Nesting of loops Debugging tools Textbook chapter 7, pages
Python quick start guide
For Loops 2 ENGR 1181 MATLAB 9. For Loops and Looped Programming in Real Life As first introduced last lecture, looping within programs has long been.
Functions 1 ENGR 1181 MATLAB 14.
B065: PROGRAMMING OPERATORS AND SELECTION 1. Starter  Have a go at the All Logic Signs activity.  COMP1  Programming  8 Selection  All Logic Signs.xls.
Slide deck by Dr. Greg Reese Miami University MATLAB An Introduction With Applications, 5 th Edition Dr. Amos Gilat The Ohio State University Chapter 6.
Engineering 1020 Introduction to Programming Peter King Winter 2010.
Selection Programming EE 100. Outline introduction Relational and Logical Operators Flow Control Loops Update Processes.
For Loops 1 ENGR 1181 MATLAB 8. For Loops and Looped Programming in Real Life Looping within programs has long been a useful tool for completing mundane.
ENG 1181 College of Engineering Engineering Education Innovation Center MAT – Conditional Statements Topics: 1.Conditional statements if-end if-else-end.
1. We’ve learned that our programs are read by the compiler in order, from top to bottom, just as they are written The order of statement execution is.
1 Flow of control Sequential Executing instructions one by one, in exact order given Selection Choosing to execute a particular set of statements depending.
CMPS 1371 Introduction to Computing for Engineers CONDITIONAL STATEMENTS.
ENGR-25_Programming-3.ppt 1 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Bruce Mayer, PE Licensed Electrical.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand how decisions are made in a computer ❏ To understand the logical.
Review for Exam2 Key Ideas 1. Key Ideas: Boolean Operators (2 > 3) || (3 < 29.3) A.True B.False C.Impossible to determine (22 > 3) && (3 > 29.3) A.True.
CS 170 – INTRO TO SCIENTIFIC AND ENGINEERING PROGRAMMING.
What does C store? >>A = [1 2 3] >>B = [1 1] >>[C,D]=meshgrid(A,B) c) a) d) b)
Saeed Ghanbartehrani Summer 2015 Lecture Notes #5: Programming Structures IE 212: Computational Methods for Industrial Engineering.
Conditional Expression One of the most useful tools for processing information in an event procedure is a conditional expression. A conditional expression.
IDL Tutorials: Day 4 Goal: Learn some programming techniques: Relational operators, conditional statements, boolean operators, loops Maria Kazachenko
Introduction to Matlab Module #4 Page 1 Introduction to Matlab Module #4 – Programming Topics 1.Programming Basics (fprintf, standard input) 2.Relational.
Chapter 4 Controlling Execution CSE Objectives Evaluate logical expressions –Boolean –Relational Change the flow of execution –Diagrams (e.g.,
Introduction to Engineering MATLAB - 13 Agenda Conditional statements  If – end  If – else – end  if – elseif – else - end.
ENG 1181 College of Engineering Engineering Education Innovation Center P. 1 MAT - Conditional Statements Topics Covered: 1. if based conditional statements.
2D Plots 2 ENGR 1181 MATLAB 13. Plotting in the Real World 2D plots generated by MATLAB can be used in a variety of fields, including the one shown here,
While Loops ENGR 1181 MATLAB 10.
Matlab tutorial course Lesson 4: Writing your own functions: programming constructs
Array Creation ENGR 1181 MATLAB 2. Civil engineers store seismic data in arrays to analyze plate tectonics as well as fault patterns. These sets of data.
Array Operations ENGR 1181 MATLAB 4.
Conditional Logic in MATLAB By Bruce Raine. How to do a basic IF – END structure in MATLAB if MATLAB Commands end i.e. do the MATLAB commands if the conditional.
# 1# 1 Nested If Statements in VBA What is a compound condition that we evaluate? What is a Nested If statement? How do we use ElseIf? CS 105 Spring 2010.
1 Conditional Statements + Loops ผศ. ดร. อนันต์ ผลเพิ่ม Anan Phonphoem
Shortcoming of the FOR-DO loop When you use the FOR-DO loop you must know how many times you want to perform an action. What if you didn’t know how many.
Program Structures Chapter 5. 5 Branching Allows different code to execute based on a conditional test. if, if-else, and switch statements.
Array Accessing and Strings ENGR 1187 MATLAB 3. Today's Topics  Array Addressing (indexing)  Vector Addressing (indexing)  Matrix Addressing (indexing)
February 25,  The BDE(Begin-During-End) event.  Worksheet – Exercise # 9 Instructions  2nd Period Test.
Flow Control in Imperative Languages. Activity 1 What does the word: ‘Imperative’ mean? 5mins …having CONTROL and ORDER!
4 - Conditional Control Structures CHAPTER 4. Introduction A Program is usually not limited to a linear sequence of instructions. In real life, a programme.
Logical Expressions ENGR 1181 MATLAB 6. Logical Expressions in Real Life Sorting objects in manufacturing processes can be accomplished automatically.
LESSON 5 LOOPING AND BRANCHING Azalya Rahmatika Fathul Fithrah JURUSAN MATEMATIKA FAKULTAS MATEMATIKA DAN ILMU PENGETAHUAN ALAM UNIVERSITAS SYIAH KUALA.
 Very often when you write code, you want to perform different actions for different decisions. You can use conditional statements in your code to do.
1 COMS 261 Computer Science I Title: C++ Fundamentals Date: September 23, 2005 Lecture Number: 11.
PHP Condtions and Loops Prepared by Dr. Maher Abuhamdeh.
ITEC 2600 Introduction to Analytical Programming
Introduction to Programming for Mechanical Engineers (ME 319)
Scripts & Functions Scripts and functions are contained in .m-files
MATLAB – Basic For Loops
Logical Operations In Matlab.
Visual Basic – Decision Statements
Conditional Statements
Chapter 4 Select…Case Multiple-Selection Statement & Logical Operators
ICT Programming Lesson 3:
Selections and Loops By Sarah, Melody, Teresa.
Presentation transcript:

Conditional Statements ENGR 1187 MATLAB 7

Conditional Statements in Real Life A Fluorescence Activated Cell Sorter (FACS) sorts cells based on predetermined conditions. Based on which conditions are met, one of 3 events occur: (1) a positive charge is applied to the cell, (2) a negative charge is applied, or (3) there is no charge applied. Based on charge, the cells will be sorted according to these conditions.

Today's Learning Objectives  Explain how conditional statements (e.g., if- end, if-else-end, switch-case) are used to make decisions.

Review from Prep Reading:  Conditional statements allow MATLAB to make decisions based on whether a certain condition is met.  If it is met: a specified set of actions is taken.  If it is not met: a different set of actions is taken.

Example Suppose you buy a lottery ticket. Your subsequent actions will likely be different depending whether or not you win…

Example If I win the lottery I will…  Quit my job!  Buy a lake house!  Throw a huge party! If I do not win I will…  Keep attending work  Continue making awesome PowerPoints about MATLAB

If-End Statements in MATLAB  Each 'if' must have a corresponding 'end'  The conditional expressions can contain relational/logical operators if conditional expression …program code end

If-Else-End Structures if x<1 …code 1 else …code 2 end  If the condition evaluates to true, code 1 is executed and code 2 is skipped  Otherwise… if the condition is not met, code 2 is executed and code 1 is skipped

Lottery Example Lottery = input('Did you win the lottery? 1=yes, 0=no') if lottery == 1 quit job buy lake house throw huge party else keep job keep making PPTs end

If - Elseif - Else - End if conditional …code 1 elseif conditional …code 2 else conditional …code 3 end

If – Elseif – Else – End Example Calculate a tip based on a restaurant bill:  Bill less than $10: Tip is $1.80  Bill between $10 and $60 Tip is 18%  Bill above $60 Tip is 20% Else If bill < $ 10 tip = $ 1.80 ElseIf $ 10 < bill < $ 60 tip = bill * 0.20 tip = bill * 0.18 False True End

If – Elseif – Else – End Example bill =input('Enter the amount of the bill in dollars:') if (bill<=10) tip = 1.8; elseif (bill>10) & (bill<=60) tip= bill*0.18; else tip= bill*0.2; end

Important Takeaways  Every if MUST have an end  Programs can have as many if statements as you want  Programs can perform the same task using different combinations of if-end, if-else-end, and if-elseif-else-end statements  Else is optional and it doesn't require a conditional statement.

Preview of Next Class  For Loops 1 How do we repeat code 10 times? 1000 times? times? Examples of basic for-end loops For-end loops with vectors Array accessing in for-end loops with vectors

What’s Next?  Review today’s Quiz #07  Open the in-class activity from the EEIC website and we will go through it together.  Then, start working on MAT-07 homework.  Prepare for next class by reading about Advanced For Loops