how do i change subfunctions to a switch

조회 수: 2 (최근 30일)
gb
gb 2019년 11월 11일
댓글: Walter Roberson 2019년 11월 12일
hi im working on a code which has muliple subfunctions
function main
question 1
calls function 1
quesion 2
calls function 2
question 3
calls function 3
end
function 1 ()
end
function 2 ()
end
function 3 ()
end
question: how do i combine the last three functions to a switch such that when i input the question number it solves the particular question?

채택된 답변

Thorsten
Thorsten 2019년 11월 11일
switch question
case 1
% code of function 1
case 2
% code of function 2
case 3
% code of function 3
otherwise
error('Wrong number, must be 1, 2, or 3.')
end
  댓글 수: 2
Thorsten
Thorsten 2019년 11월 12일
Just put the code in the main function.
Walter Roberson
Walter Roberson 2019년 11월 12일
function main
question 1
entire code for function 1 excluding the "function" header and "end"
quesion 2
entire code for function 2 excluding the "function" header and "end"
question 3
entire code for function 3 excluding the "function" header and "end"
end

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by