Switch case (how to use for case insensitive string check)

28 visualizaciones (últimos 30 días)
Har Hind
Har Hind el 17 de Feb. de 2012
This might be a dumb question, but i did not seem to find an answer.
I´m using switch statement like this,
switch str
case {'power','POWER','Power'.....}
is there any way for me write the string for comparison in the case statement only once, but which also covers all case combinations something like, strcmpi
Thanks in advance. Best Regards, Hss

Respuestas (2)

Oleg Komarov
Oleg Komarov el 17 de Feb. de 2012
switch lower(str)
case 'power'
end
Just lower the case of your control variable.

Andrei Bobrov
Andrei Bobrov el 17 de Feb. de 2012
try
str1 = lower(str);
switch str1
case 'power'

Categorías

Más información sobre MATLAB en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by