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

댓글 수: 1

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

댓글을 달려면 로그인하십시오.

 채택된 답변

Jos (10584)
Jos (10584) 2014년 5월 7일

0 개 추천

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 MATLAB에 대해 자세히 알아보기

태그

질문:

2014년 5월 7일

답변:

2014년 5월 7일

Community Treasure Hunt

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

Start Hunting!

Translated by