MATLAB: Does the SWITCH statement in MATLAB 7.4 (R2007a) not throw an error when there are multiple cases with same value

caseduplicateMATLABswitch

In a SWITCH statement such as
switch a
case 1
disp(a);
case 1
disp(a+1);
end
The second case can never be executed. I expect MATLAB to give an error in this situation, like C would.

Best Answer

This is another difference between the SWITCH construct in C and in MATLAB, and is expected behavior.
In general, cases may be specified by expressions instead of literals in MATLAB. In this situation, one may not be able to determine whether case expressions are equal until runtime.