필터 지우기
필터 지우기

Equivalent to "GOTO" to jump to different mfiles?

조회 수: 4 (최근 30일)
Stenila  Simon
Stenila Simon 2017년 11월 11일
편집: Stenila Simon 2017년 11월 11일
I am trying to write a code that will ask the user for an input, and depending on the input, different mfiles will be run. Say, for example, when this code runs, it will display: "Please input section code:" and then the user can input any value from 1 to 5, and if they input "1", a separate mfile that contains all the info for section 1 will run, for input "2", a different mfile for section 2, etc.
Is there something like "goto" that I can use in Matlab for this purpose?
EDIT: I figured it out nevermind!

답변 (1개)

John D'Errico
John D'Errico 2017년 11월 11일
NO. Why would you possibly need it? Learn to use MATLAB, instead of trying to use some other language inside MATLAB. There are many ways to do this. Simplest is a switch.
switch SectionNum
case 1
Sect1mfile
case 2
Sect2mfile
otherwise
error('the sky is falling!')
end
Just call the desired m-file in the corresponding branch. You can have as many cases as you want.
Or do the same thing using an if/elseif form instead.

카테고리

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