Programmatically get valid switch/case values

Posted by craigim on Stack Overflow See other posts from Stack Overflow or by craigim
Published on 2013-06-26T16:30:27Z Indexed on 2013/06/27 22:21 UTC
Read the original article Hit count: 109

Filed under:

When MATLAB scans through cases in a switch/case block, does it remember the values that it skips, and is it possible to access that list? I have a few functions with long switch\case block and I would like to have them return a list of valid case values if they make it down to otherwise. For instance, I have a function that returns a set of optical constants for a material. It currently has about 20 different materials and it is growing as I consider new ones.

I realize I can brute-force it and just re-type all of the valid cases into a cell array under otherwise and have the function throw an error and return the list of valid responses, but maintaining both lists without errors or laziness creeping in over time is challenging.

© Stack Overflow or respective owner

Related posts about matlab