A Question on a Simple Loop

2 ビュー (過去 30 日間)
Zahra kamkar
Zahra kamkar 2014 年 5 月 13 日
コメント済み: Zahra kamkar 2014 年 5 月 14 日
Hello. My problem: We have 5 machines. We wanna play each of these machines 1000 times (we call each 1000 plays a TASK). In each time, the machine gives us a reward (randomly). We wanna check that the mean reward of which one of these TASKs is more than others (maximum). I wrote this code but it doesn't work well. Why?
for j=1:5
h=0;
for i=1:1000
rew=randn(1);
sum=rew+h;
end
mean(j)=sum./1000; [value,index]=max(mean(j))
end end
Thanks in advance
  2 件のコメント
Walter Roberson
Walter Roberson 2014 年 5 月 13 日
Do not use "sum" as the name of a variable or you will almost always encounter problems with sum() being the name of a useful MATLAB function.
Zahra kamkar
Zahra kamkar 2014 年 5 月 14 日
Thanks a lot

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

回答 (1 件)

Walter Roberson
Walter Roberson 2014 年 5 月 13 日
You never update "h" so at each point "sum" will be assigned only the latest random value.

カテゴリ

Help Center および File ExchangeStartup and Shutdown についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by