Using Otherwise to Throw Errors in a Switch Case
(Originally posted on Doug's MATLAB Video Tutorials blog.)
In some code there is an enumerated set of choices. People will use a switch case statement to check for all but one choice and then catch that last one in the 'otherwise' block of their code. However, if there is unexpected inputs, the 'otherwise' will fire when it should not.
This video shows a technique for catching this problem. It is important to catch these errors from unexpected inputs immediately, because they can have effects on your code much farther down the line. When this happens, it would be hard to trace back to the cause.
Recorded: 25 Mar 2013
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.