|
"Lin " <shenqlv@yahoo.com> wrote in message <griitd$m3l$1@fred.mathworks.com>...
> Hi all
>
> I am using a switch for my codes, it is possible to modify the cases to something as shown instead of going through all the cases? Because case 11 || 21 || 31 will undergo the same set of operations, hence it would be troublesome to cut and paste the same thing over and over again.
>
> path =[11 12 21 22 31 32 41 42 51 52 61 62]
> for path_index = 1:length(path)
>
> switch(path(path_index))
> case 11 or 21 or 31
> %perform some operation
> case 12 or 22 or 42
> %perform some operation
> end
>
> Thanks.
Hi Lin,
For a switch on numeric data, you can use an array [] to specify multiple OR cases, for a switch on character data, you can use a cell {}. See below
caseVar = 3;
switch caseVar
case [3 4 445]
disp '3 or 4 or 445'
otherwise
disp 'other number'
end
Thanks,
Sven.
|