This is a topic that many people are looking for. thevoltreport.com is a channel providing useful information about learning, life, digital marketing and online courses …. it will help you have an overview and solid multi-faceted knowledge . Today, thevoltreport.com would like to introduce to you Switch Statement in Matlab. Following along are instructions in the video below:
all right in this tutorial we are going to be talking about switch statements so sweetly them switch statements are not so different than if statements what they do is they check a condition and output a result based on that condition but theres a main difference here and if conditions we can enter any condition and the computer will check whether or not the condition is true or false but here in Als condition Im sorry and switch statements we have a variable if you pick a variable here and we define some cases it could be any number of cases and we say lets say were able is equal to 10 dude this variable is equal to 9 do this the way it was equal to 8 do this variable is equal to anything other than these numbers do that which is defined by otherwise keyword so were going to do two different examples and well also do some error checking so that you would make sure that no one enters something stupid to your program and your program will go crazy all right so the first example well be testing the results of a quiz and well basically go
through every student and say youve got an A you gotta be here to see and youve got an F and youre now passing this class so lets do that lets say leather sorry quiz rests which means result is equal to say 5 all right so lets type switch statements which is our keyword gap to type its sort of mid-level understand what youre doing then your keyword which is quiz rest you have to press ENTER and you define our first case which is case if the student gets 5 will say well you passed you double single code you passed with flying colors all right case for if youve got a four you say well display it looks fine case three you say display good enough not anymore and you say if its less dense three you say otherwise any other cases then five four three easy play sorry you failed you failed oh I cant type all right and you finished up with and all right you passed with flying colors oh I have a typo here okay so this is our case but what if the student has a crazy value like its lets say weve asked
the student to enter its a quiz result and it entered 100 well its not a good thing right so youre going to use an if statement to error check so let me copy that and create a great checker which Ive already created it and go there and copy and paste and we say well this is our case right but lets change something so that if someone enters I dont know anything other than five four three two one were going to give an error mister say lets say if quiz rest is less than zero and sorry or quiz rest its greater than six sorry five were going to say not a real thing right because its a problem obviously its a problem if its not if its between that between the values that we were given like five four three two were going to define else and say well execute this function right but theres a mistake here as you can see here it says hey warning theres a problem here and lets see because I dont what problem is but we better sell you with some youll be stopped doing debugging here so you say look line
one and ends might be missing yes because we have to find an if statement but we have forgot the ends so you type and and done so dont forget to save this thing so lets say leather sorry quiz res is equal to whats a crazy number right 1000 alright press Enter call a great checker sorry great checker dont forget to spell the exactly its spelled in your file name great checker and not a real thing just like we expected what about a normal thing quiz wrath sorry quiz res s3 call great checker good just like their fault ok Ill do another example this one will be easy so let me define another one here Ill create another file script this time again plane ticket so in this example were going to enter a city name and the program will tell us how much it will cost if we go there by your plane so this is a fire statement switch switch city lets get me any city that will be our variable that were going to define switch city theres a problem here I dont know why anyway did I type it wrong no its an end
weird so okay switch city so first case if its Boston will say well $400 $400 alright what about another city like I dont know analog Paris display thousand dollars oops and the last case work at London these are really basic cities okay think of them other than 200 because its really hard to get to London all right so we have defined our statement as I say city is equal to what Boston all right lets call our plane ticket $435 Im really curious what happens when I enter anything other than that right city is equal to lets say Istanbul and call our plane ticket nothing happened because we forgot something really critical otherwise well if theres no otherwise how we are going to know that well we could some write something like this right otherwise display I dont I dont know simple is that right so clear this up call it again I dont know all right thats all about switch statements Im not used it many I not use it as much as I would like to but you might want to use it thank you for watching this tutorial and I will see you in another tutorial
Switch Statement, MATLAB (Programming Language), Programming Language (Software Genre), matlab tutorial, matlab course, matlab, matlab free tutorial
Thank you for watching all the articles on the topic Switch Statement in Matlab. All shares of thevoltreport.com are very good. We hope you are satisfied with the article. For any questions, please leave a comment below. Hopefully you guys support our website even more.