フィルターのクリア

goto command in matlab

31 ビュー (過去 30 日間)
RAAD AL-DULAIMI
RAAD AL-DULAIMI 2015 年 10 月 22 日
コメント済み: Guillaume 2015 年 10 月 22 日
i have code consist from 80 step, at step 60 i have condition, if not true, it should be jump to step 30, my question, is there (goto) or somthing same command in matlab

採用された回答

Guillaume
Guillaume 2015 年 10 月 22 日
There's no goto in matlab, and there is no need to. You could just as well code your algorithm as:
%... step 1 to 29
condition = false;
while ~condition
%... step 30 to 60
condition = sometest
end
%... step 61 to 80
  2 件のコメント
Guillaume
Guillaume 2015 年 10 月 22 日
編集済み: Guillaume 2015 年 10 月 22 日
Another option is to build your code as a state machine. A simple way to implement a state machine is just with a while loop and a switch. With 80 states, it's going to be a bit unwieldy to code:
step = 1;
while true
switch step
case 1
%do step 1
step = 2;
%... case 2 to 59
case 60
%do step 60
if somecondition
step = 61;
else
step = 30;
end
%... case 61 to 79
case 80
%do step 80
break;
end
end
RAAD AL-DULAIMI
RAAD AL-DULAIMI 2015 年 10 月 22 日
編集済み: RAAD AL-DULAIMI 2015 年 10 月 22 日
thanks for your response,i have code consist from 80 step, at step 60 i have condition , computed variable value and compare it with value computed at step 30, if not true, it should be jump to step 30, to repeat calculation with new step to find new value, i need to jump to step 30 to repeat computations between them

サインインしてコメントする。

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2015 年 10 月 22 日
Goto is not available in basic MATLAB but is available in a File Exchange Contribution for the amusement of those who know not to use GOTO, and for the frustration of those who insist they need GOTO.
  1 件のコメント
Guillaume
Guillaume 2015 年 10 月 22 日
'amusement' is a key word here. That FEX contribution should not be used for anything else. I don't think the warning is strong enough on the FEX page and we may end up having some people trying to use it without understanding the implication.
That goto is basically an interpreter built on top of matlab own interpreter. As soon as you hit a goto, you're simply eval'ing the rest of the program line by line!

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by