there is a way that if clause it is execute

1 回表示 (過去 30 日間)
Salvatore Mazzarino
Salvatore Mazzarino 2012 年 9 月 20 日
Here it is a piece of code:
x = rand;
if x < 1E-6
do-something
end
if I execute this piece of block in loop, the program never execute if clause because x is always bigger. how can I enter in that block?

採用された回答

per isakson
per isakson 2012 年 9 月 20 日
編集済み: per isakson 2012 年 9 月 20 日
Try this:
for ii = 1 : 1e7
x = rand;
if x < 1E-6
disp( 'do-something' )
end
end
do-something
do-something
do-something
do-something
do-something
do-something
do-something
Thus, in this case it was executed seven times. (R2012a,64bit,Win7)

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by