best way to enter only one time in a if block

2 ビュー (過去 30 日間)
Salvatore Mazzarino
Salvatore Mazzarino 2012 年 9 月 16 日
I have a for cycle
for n= 1: 100
x=rand()*10;
if x > 5
do something
end
end
When I execute this cycle it happens that if x is major than 5, the program enter in if clause. I would create a way that enter in if clause only one time even if the condition is true.which could be the best way?In Java I'd created this using boolean but matlab doesn't have boolean type

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2012 年 9 月 16 日
編集済み: Azzi Abdelmalek 2012 年 9 月 16 日
test=0
for n= 1: 100
x=rand()*10;
if x > 5 & test==0
%do something
test=1
end
end
  1 件のコメント
Azzi Abdelmalek
Azzi Abdelmalek 2012 年 9 月 16 日
matlab does have boolean type

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDebugging and Analysis についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by