2016-07-12 8 views
-4

MATLABでプログラムを書く際に問題があります。私は問題を解決するためにgoto-statementが必要です。コードは次のとおりです。MATLABにgoto-statementsの代替手段はありますか?

for i=1:n 
1: newT=T(i)+unifrnd(-r,r); 
    newT=P(i)+unifrnd(-r,r); 
    if newT<Tmax && newT>Tmin && newP<Pmax && newP>Pmax 
     bestT=newT bestP=newP 
    else 
     go to 1 
    end 
end 

goto-statementの代替手段はありますか?

+0

(http://stackoverflow.com/questions/35655101/matlab-goto-sort-of)[GOTO(ソートの)をMathWorks社のMATLAB] – shamalaia

答えて

1

あなたの探しているものは?

for i=1:n 
    loop = true; 
    while loop 
     newT=T(i)+unifrnd(-r,r); 
     newT=P(i)+unifrnd(-r,r); 
     if newT<Tmax && newT>Tmin && newP<Pmax && newP>Pmax 
      bestT=newT bestP=newP 
      loop = false; 
     end 
    end 
end 
+1

の可能性の重複はイエスのよう.something拡張子、ありがとうございました。やってみます –

関連する問題