![Page 1: Conditional Statements ENGR 1187 MATLAB 7. Conditional Statements in Real Life A Fluorescence Activated Cell Sorter (FACS) sorts cells based on predetermined](https://reader035.vdocuments.mx/reader035/viewer/2022080922/56649ec45503460f94bcee0b/html5/thumbnails/1.jpg)
Conditional StatementsENGR 1187MATLAB 7
![Page 2: Conditional Statements ENGR 1187 MATLAB 7. Conditional Statements in Real Life A Fluorescence Activated Cell Sorter (FACS) sorts cells based on predetermined](https://reader035.vdocuments.mx/reader035/viewer/2022080922/56649ec45503460f94bcee0b/html5/thumbnails/2.jpg)
Conditional Statementsin 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.
![Page 3: Conditional Statements ENGR 1187 MATLAB 7. Conditional Statements in Real Life A Fluorescence Activated Cell Sorter (FACS) sorts cells based on predetermined](https://reader035.vdocuments.mx/reader035/viewer/2022080922/56649ec45503460f94bcee0b/html5/thumbnails/3.jpg)
Today's Learning Objectives Explain how conditional statements
(e.g., if-end, if-else-end, switch-case) are used to make decisions.
![Page 4: Conditional Statements ENGR 1187 MATLAB 7. Conditional Statements in Real Life A Fluorescence Activated Cell Sorter (FACS) sorts cells based on predetermined](https://reader035.vdocuments.mx/reader035/viewer/2022080922/56649ec45503460f94bcee0b/html5/thumbnails/4.jpg)
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.
![Page 5: Conditional Statements ENGR 1187 MATLAB 7. Conditional Statements in Real Life A Fluorescence Activated Cell Sorter (FACS) sorts cells based on predetermined](https://reader035.vdocuments.mx/reader035/viewer/2022080922/56649ec45503460f94bcee0b/html5/thumbnails/5.jpg)
ExampleSuppose you buy a lottery ticket.
Your subsequent actions will likely be different depending whether or not you win…
![Page 6: Conditional Statements ENGR 1187 MATLAB 7. Conditional Statements in Real Life A Fluorescence Activated Cell Sorter (FACS) sorts cells based on predetermined](https://reader035.vdocuments.mx/reader035/viewer/2022080922/56649ec45503460f94bcee0b/html5/thumbnails/6.jpg)
ExampleIf 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
![Page 7: Conditional Statements ENGR 1187 MATLAB 7. Conditional Statements in Real Life A Fluorescence Activated Cell Sorter (FACS) sorts cells based on predetermined](https://reader035.vdocuments.mx/reader035/viewer/2022080922/56649ec45503460f94bcee0b/html5/thumbnails/7.jpg)
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
![Page 8: Conditional Statements ENGR 1187 MATLAB 7. Conditional Statements in Real Life A Fluorescence Activated Cell Sorter (FACS) sorts cells based on predetermined](https://reader035.vdocuments.mx/reader035/viewer/2022080922/56649ec45503460f94bcee0b/html5/thumbnails/8.jpg)
If-Else-End Structuresif 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
![Page 9: Conditional Statements ENGR 1187 MATLAB 7. Conditional Statements in Real Life A Fluorescence Activated Cell Sorter (FACS) sorts cells based on predetermined](https://reader035.vdocuments.mx/reader035/viewer/2022080922/56649ec45503460f94bcee0b/html5/thumbnails/9.jpg)
Lottery ExampleLottery = input('Did you win the lottery? 1=yes, 0=no')
if lottery == 1quit jobbuy lake housethrow huge party
elsekeep jobkeep making PPTs
end
![Page 10: Conditional Statements ENGR 1187 MATLAB 7. Conditional Statements in Real Life A Fluorescence Activated Cell Sorter (FACS) sorts cells based on predetermined](https://reader035.vdocuments.mx/reader035/viewer/2022080922/56649ec45503460f94bcee0b/html5/thumbnails/10.jpg)
If - Elseif - Else - Endif conditional
…code 1
elseif conditional
…code 2
else conditional
…code 3
end
False
ElseIfconditional
True
False
TrueCode 1
End
Ifconditional
Code 2 Code 3
![Page 11: Conditional Statements ENGR 1187 MATLAB 7. Conditional Statements in Real Life A Fluorescence Activated Cell Sorter (FACS) sorts cells based on predetermined](https://reader035.vdocuments.mx/reader035/viewer/2022080922/56649ec45503460f94bcee0b/html5/thumbnails/11.jpg)
If – Elseif – Else – End ExampleCalculate a tip based on a restaurant bill:
Bill less than $10:Tip is $1.80
Bill between $10 and $60Tip is 18%
Bill above $60Tip is 20%
Else
If bill < $
10
tip = $ 1.80
ElseIf $ 10 < bill < $ 60
tip = bill * 0.20
tip = bill * 0.18
False
FalseTrue
True
End
![Page 12: Conditional Statements ENGR 1187 MATLAB 7. Conditional Statements in Real Life A Fluorescence Activated Cell Sorter (FACS) sorts cells based on predetermined](https://reader035.vdocuments.mx/reader035/viewer/2022080922/56649ec45503460f94bcee0b/html5/thumbnails/12.jpg)
If – Elseif – Else – End Examplebill =input('Enter the amount of the bill in dollars:')
if (bill<=10)tip = 1.8;
elseif (bill>10) & (bill<=60)tip= bill*0.18;
elsetip= bill*0.2;
end
![Page 13: Conditional Statements ENGR 1187 MATLAB 7. Conditional Statements in Real Life A Fluorescence Activated Cell Sorter (FACS) sorts cells based on predetermined](https://reader035.vdocuments.mx/reader035/viewer/2022080922/56649ec45503460f94bcee0b/html5/thumbnails/13.jpg)
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.
![Page 14: Conditional Statements ENGR 1187 MATLAB 7. Conditional Statements in Real Life A Fluorescence Activated Cell Sorter (FACS) sorts cells based on predetermined](https://reader035.vdocuments.mx/reader035/viewer/2022080922/56649ec45503460f94bcee0b/html5/thumbnails/14.jpg)
Preview of Next Class For Loops 1
• How do we repeat code 10 times? 1000 times? 1010 times?
• Examples of basic for-end loops• For-end loops with vectors• Array accessing in for-end loops with
vectors
![Page 15: Conditional Statements ENGR 1187 MATLAB 7. Conditional Statements in Real Life A Fluorescence Activated Cell Sorter (FACS) sorts cells based on predetermined](https://reader035.vdocuments.mx/reader035/viewer/2022080922/56649ec45503460f94bcee0b/html5/thumbnails/15.jpg)
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