how do you increment a count and repeat a code multiple times

2 ビュー (過去 30 日間)
James
James 2014 年 4 月 2 日
編集済み: lvn 2014 年 4 月 2 日
random numbers a1, b1 and b2, when the numbers will either output a1=b1 or a1=b2 - if B1 is identical to A1 increment count1. - if B2 is identical to A1 increment count2.
<count1> and <count2> are both initialised to zero at the start and so that the code is repeated 10000 times
thanks

回答 (1 件)

lvn
lvn 2014 年 4 月 2 日
編集済み: lvn 2014 年 4 月 2 日
For random numbers between 0 and 10
count1=0; count2=0;
for p=1:10000
a1=round(rand(1)*10);
b1=round(rand(1)*10);
b2=round(rand(1)*10);
if b1==a1
count1=count1+1;
end;
if b2==a1
count2=count2+1;
end;
end
count1
count2
output:
count1 =
920
count2 =
981

カテゴリ

Help Center および File ExchangeBiological and Health Sciences についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by