MATLAB Conditional Statements ENGR 1181 Presentation by Annie Abell.

Slides:



Advertisements
Similar presentations
If Statements, Try Catch and Validation. The main statement used in C# for making decisions depending on different conditions is called the If statement.
Advertisements

The If Then Else Statement Using JavaScript TIP The If Statement is the fundamental control structure that allows branches in the flow of control in a.
CYCLOMATIC COMPLEXITY 1. Invented by Thomas McCabe (1974) to measure the complexity of a program ’ s conditional logic Cyclomatic complexity of graph.
Making Decisions in Python Sec 9-10 Web Design. Objectives The student will: Understand how to make a decision in Python Understand the structure of an.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 4 Making Decisions in a Program.
Week 6 - Programming I So far, we’ve looked at simple programming via “scripts” = programs of sequentially evaluated commands Today, extend features to:
Fall 2004ENGR 111A MatLab – Palm Chapter 4, Part 2 The if and switch structure Class 10.1 Sections: 4.4 and 4.6.
MATLAB Loops and Branching.
General Computer Science for Engineers CISC 106 Lecture 05 Dr. John Cavazos Computer and Information Sciences 2/20/2009.
Tutorial 4 Decision Making with Control Structures and Statements Section A - Decision Making JavaScript Tutorial 4 -Decision Making with Control.
Programming with MATLAB. Relational Operators The arithmetic operators has precedence over relational operators.
Detecting Assimilation. last year / l a: s tF E:/ would you / w u dV u/ and you did you put you don’t you next year want you glad you without your help.
- Meeting 5 – Making Decision By: Felix Valentin, MBA.
More on Conditionals. Objectives Write the converse, inverse, and contrapositive of a given conditional statement. Determine the premise and conclusion.
CS0004: Introduction to Programming Relational Operators, Logical Operators, and If Statements.
Python – Making Decisions Lecture 02. Control Structures A program that only has one flow is useful but limited. We can use if statements to make these.
Engineering 1020 Introduction to Programming Peter King Winter 2010.
Selection Programming EE 100. Outline introduction Relational and Logical Operators Flow Control Loops Update Processes.
ENGR 1320 Final Review - Programming Major Topics: – Functions and Scripts – Vector and Matrix Operations in Matlab Dot product Cross product – Plotting.
ENG 1181 College of Engineering Engineering Education Innovation Center MAT – Conditional Statements Topics: 1.Conditional statements if-end if-else-end.
Conditional Statements ENGR 1187 MATLAB 7. Conditional Statements in Real Life A Fluorescence Activated Cell Sorter (FACS) sorts cells based on predetermined.
Chapter 5 Decisions. Outline and Objectives Relational and Logical Operators If Blocks Select Case Blocks.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley STARTING OUT WITH Python Python First Edition by Tony Gaddis Chapter 4 Decision.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand how decisions are made in a computer ❏ To understand the logical.
Conditional Probability More often than not, we wish to express probabilities conditionally. i.e. we specify the assumptions or conditions under which.
Synthesis ENGR 1181 MATLAB 11. Topics  No new material  Covers topics that will be on the Midterm 2 Exam MATLAB 01 – Program Design MATLAB 02 – Introduction.
Conditionals Sarah Morris. What is a conditional?  A conditional sentence is a sentence containing the word if.  Something will happen if a condition.
Conditional Expression One of the most useful tools for processing information in an event procedure is a conditional expression. A conditional expression.
Introduction to Matlab Module #4 Page 1 Introduction to Matlab Module #4 – Programming Topics 1.Programming Basics (fprintf, standard input) 2.Relational.
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.1.
Introduction to Engineering MATLAB - 13 Agenda Conditional statements  If – end  If – else – end  if – elseif – else - end.
Unit 2- Developing Writing Skills 4
ENG 1181 College of Engineering Engineering Education Innovation Center P. 1 MAT - Conditional Statements Topics Covered: 1. if based conditional statements.
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.
How to Win the Lottery By: Jackson Correll. Lottery Ticket  You can buy them from the Gas station and  Another thing is that, you have to be 18 years.
Conditional statements and boolean expressions Arithmetic, relational and logical operators.
Chapter 4 Select … Case Multiple-Selection Statement & Logical Operators 1 © by Pearson Education, Inc. All Rights Reserved. -Edited By Maysoon.
Control Structure  What is control Structure?  Types of Controls  Use the control structure in VBScript.  Example Summery.
WRITING AN OPINION PARAGRAPH. An opinion is a thought or belief about someone or something EX[PRESSING OPINIONS.
Writing an Opinion Piece. Expressing an Opinion An opinion is a thought or belief about someone or something.
 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.
Chapter 4 MATLAB Programming
Chapter 4 Select…Case Multiple-Selection Statement & Logical Operators
Programming Fundamentals
“Putting a Face to the Name...”
Chapter 4 Select…Case Multiple-Selection Statement & Logical Operators
IF if (condition) { Process… }
Comprehensive Test tomorrow Maintenance Sheet 25 Due
Problem Solving Lab – Part C
Selection Statements Chapter 4 Attaway MATLAB 4E.
Chapter 4 Select…Case Multiple-Selection Statement & Logical Operators
Logical Operations In Matlab.
Visual Basic – Decision Statements
MatLab – Palm Chapter 4, Part 2 The if and switch structure
Intro to Programming CURIE 2011.
MatLab – Palm Chapter 4, Part 2 The if and switch structure
Conditional Statements
Conditional Logic Presentation Name Course Name
Chapter 4 Select…Case Multiple-Selection Statement & Logical Operators
Chapter 4 Select…Case Multiple-Selection Statement & Logical Operators
‘If’ statements, relational operators, and logical operators
Selection—Making Decisions
Chapter 3: Selection Structures: Making Decisions
Chapter 4 Select…Case Multiple-Selection Statement & Logical Operators
Selection Statements Chapter 4 Attaway MATLAB 5E.
Default values of parameters
Chapter 4 Select…Case Multiple-Selection Statement & Logical Operators
Presentation transcript:

MATLAB Conditional Statements ENGR 1181 Presentation by Annie Abell

Todays Topics Conditional Statements: if-end if-else-end if-elseif-else-end How to structure conditional statements How to use relational & logical operators with conditional statements

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 you win or not…

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

Rules about 'If Statements' 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. It does not require a conditional statement.