From the course: MATLAB 2018 Essential Training

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Apply conditional logic using Switch

Apply conditional logic using Switch - MATLAB Tutorial

From the course: MATLAB 2018 Essential Training

Start my 1-month free trial

Apply conditional logic using Switch

- [Instructor] In the previous movie, I showed you how to handle different ranges of values using if...and, if...else statements. Those statements are useful for one or two cases, but they can quickly become unwieldy when you have more than three possibilities. In this movie, I will show you how to use the switch statement to handle multiple cases. I have a blank command window in front of me, but what I really need to do is create a script. So on the "Home" tab, I will go over to the "New Script" button and click it, and that gives me a new editor. I could also have pressed control N to create a new script. I want to define a function, so I will type that keyword "function". The return variable that I will return out of the function, will be "spc", and I'm setting that variable equal to the result of the function, which I will call "spcode", and you'll see why in a second. I don't want to pass in any arguments, so I will type a blank left and right parentheses. I'll press enter twice…

Contents