I was reading this code and at line 97 I found the following code:
switch lower(opts.color)
case 'rgb'
case 'opponent'
...
I've never seen empty statements (according to documentation). What does it mean?
"If lower(opts.color)
is either rgb
or opponent
then do ...
"
or
"If lower(opts.color)
is rgb
do nothing and if it's opponent
do ...
"?
If the case
block is empty, then nothing is executed for that particular case. So if opt.colors
is 'rgb'
no action is taken.
The reason that the author has even bothered to include it as a case
is because if they hadn't, the code within the otherwise
block (which sets opts.color
to 'hsv'
because the supplied colorspace wasn't recognized/valid) would be executed if opt.colors
was 'rgb'
which obviously is undesirable behavior.
The block is the functional equivalent of
if ~strcmpi(opts.color, 'rgb')
switch lower(opts.color)
case 'opponent'
% Do stuff
case 'hsv'
% Do other stuff
otherwise
% Throw warning
end
end
The syntax for a case
block which matches several values requires the use of a cell array for the case expression.
switch lower(opts.color)
case {'rgb', 'opponent'}
...
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With