Multple switch expressions needed to run
Mostrar comentarios más antiguos
I need some help on executing multiple cases when using the "Switch" function. An example to clearify this
scenario = {'a', 'b'}
switch scenario
case 'a'
disp('Hello ')
case 'b'
disp('World')
case 'c'
disp('dont display')
end
The output what i'm looking for word be:
'Hello '
'World'
The idea is that "Case" would check if the variable is in scenario and accordinly run it. Could anyone please give me a suggestion how I could do this elegantly? It seems this only works the other way around.
Thanks a lot!
2 comentarios
Rik
el 24 de Nov. de 2017
You could put the switch block in its own function and use cellfun or even a for-loop.
Tim Decuypere
el 25 de Nov. de 2017
Respuesta aceptada
Más respuestas (1)
KVM
el 24 de Nov. de 2017
Editada: Walter Roberson
el 24 de Nov. de 2017
scenario = {'a', 'b'}
for i=1:length(scenario);
switch scenario{i}
case 'a'
disp('Hello ')
case 'b'
disp('World')
case 'c'
disp('dont display')
end
end
Categorías
Más información sobre App Building en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!