In a switch, how can I make a case lead to a different case without repeating the code?

1 Kommentar

the cyclist
the cyclist am 7 Mai 2014
There's not enough detail here for us to give you much help. Can you give a small example of what you mean?

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Jos (10584)
Jos (10584) am 7 Mai 2014

0 Stimmen

use functions, for instance, implemented as sub-functions in your main function. Like this, perhaps:
function MainFunction (SW)
switch SW
case C1
disp('Case 1, so I will executed function One')
MyFunctionOne
case C2
disp('Case 2, but I will still execute function One, haha') ;
MyFunctionOne
case C3
disp('Case 3, nothing to do') ;
end
function MyFunctionOne
disp('Function One executing')
end

Weitere Antworten (0)

Kategorien

Mehr zu MATLAB finden Sie in Hilfe-Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by