Binornd draws '1' every time
古いコメントを表示
I'm running a script in which I use binornd(1,0.5) within a for loop, and the output is '1' every time. When I copy paste to the command window, it behaves as expected (I haven't done a full statistical test, but at least I get both '0's and '1's as outputs). In the same script, I use randi, which seems to be behaving normally..
Moving the binornd line to different positions in the script does not make a difference, and neither does adding rng('shuffle') just above. Finally, I use binornd(1,p) in another loop, where p varies on each iteration, and I also get only '1's as outputs. So it seems to be a problem specific to binornd.
5 件のコメント
Oleg Komarov
2014 年 7 月 8 日
Hard to say without the script.
Henry
2014 年 7 月 8 日
John D'Errico
2014 年 7 月 8 日
編集済み: John D'Errico
2014 年 7 月 8 日
Why are you using rng inside the loop?
Don't do a shuffle before every call! It does not make things more random. In fact, it will make things less random and it will slow down your code.
This is a common mistake people make. They think because they have a tool, that they must use it.
Henry
2014 年 7 月 8 日
Henry
2014 年 7 月 8 日
回答 (2 件)
Jos (10584)
2014 年 7 月 8 日
what if you execute
which binornd
just before the calls? Do the outputs differ based on the situation (script vs. command line). It could be that you have two different versions ...
Shashank Prasanna
2014 年 7 月 8 日
編集済み: Shashank Prasanna
2014 年 7 月 8 日
Why don't you generate all of your random numbers before hand and just use index into the array at each loop iteration? It should be faster and cleaner:
randBin = binornd(limit,0.5);
while count<limit
matrix=fastest_matrix;
a(count)=randi([1 order]);
b(count)=randi([1 order]);
t(count)=randBin(count);
...
3 件のコメント
Henry
2014 年 7 月 8 日
Shashank Prasanna
2014 年 7 月 8 日
My bad, I meant to say:
randBin = binornd(1,0.5,limit,1);
Henry
2014 年 7 月 8 日
カテゴリ
ヘルプ センター および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!