Lab 3

Chapter 4 - Selection Statements

Synopsis
In Lecture 3, we wrote a MATLAB program that interacts with users via the keyboard. A key part of handling input is checking that the user entered the correct value. In this lab, we will write selection statements to check the value of different user inputs. The topics for this lab include if statements, if-else statements, nested if-else statements, if-elseif statements, switch statements, and the menu function.


Daily Quiz

Quiz 6


Lab 3

Download and work through the m-file below
lab3_20160210.m

Answer Key

Code
lab3key_20160210.m

Output
Lab 3


Final Words

As your MATLAB programs become more elaborate, you will find that selection statements will be a particularly useful tool. Variables in your programs can hold many different values, and selection statements allow us to check those values to help dictate the flow of our code. Next, we will learn looping control statements that allow us to repeat portions of our program.