How to write a "go to" -like statement in matlab

Hi. Need a lil bit of help here. I normally work with fortran that supported a "go to" statement. Is there anyway that i could do the same ("go to" - like statement) using matlab? e.g.
if solution ==1
<do program statements A >
<do program statements B >
elseif solution ==2
<do program statements A (as previously stated above) only>
%this is where i normally used a go to previous line statement in fortran to avoid writing the same program statement twice.
end
Appreciate any help u can give

 채택된 답변

Thomas
Thomas 2012년 6월 12일

1 개 추천

I dont think there is 'goto' in MATLAB you could use
try
..
catch

댓글 수: 3

MHY
MHY 2012년 6월 12일
Not very familiar with try ..catch statement. Would u mind to roughly show me how to apply try ..catch in the example given above? appreciate your help.
Thomas
Thomas 2012년 6월 12일
then it would be easier to use the File exchange submission I have linked to..
no reason for goto or trycatch here/
Put the various statements in sub ffunction as Ilham has suggested.

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

추가 답변 (1개)

Ilham Hardy
Ilham Hardy 2012년 6월 12일

3 개 추천

Seems better to put statement A and B as seperate functions or scripts. Then you can call them whenever and wherever you want.

카테고리

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

질문:

MHY
2012년 6월 12일

Community Treasure Hunt

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

Start Hunting!

Translated by