switch
Programming
Multi-way branch. Compares the switch expression against each case value. Executes the first matching case block. The otherwise block runs if no case matches. Unlike C, no fall-through between cases.
Syntax
switch expr
case val1
...
case val2
...
otherwise
...
endExamples
method = 'euler';
switch method
case 'euler'
disp('First order')
case 'rk4'
disp('Fourth order')
otherwise
disp('Unknown')
end▶ RunSee Also
Try SimLab — Free MATLAB® Alternative
466 functions. Runs in your browser. No install.
Open SimLab