Using binornd function - problem with draw variability
显示 更早的评论
Hi, I have a problem with the binornd function in simulink. I use it:
v=binornd(1,p)

'p' is variable from 0 to 1, forming on a curve (the same curve in each simulation) (the attached screen - probability; the 1st graph).
Below (2nd graph in attached screen) it is the result of the draw, with time step 0.01 sec. It is the same result for each time.
I wish that this distribution will be varies in accordance with the pseudo-random nature of the function binornd.
Do you know how to set this function, that for every time changed the results of the draw?
(It seems as grain was always the same - in r programm I can change it, but in matlab i don't know)
Regards, Sz.
回答(1 个)
Roger Stafford
2016-5-16
By writing “binornd(1,p)” you are restricting yourself to the values 0 and 1 with probabilities 1-p and p. To get a larger range use “binornd(n,p)” which will have a range of 0 to n. See:
http://www.mathworks.com/help/stats/binornd.html
2 个评论
Szymon Wer
2016-5-17
编辑:Szymon Wer
2016-5-17
Roger Stafford
2016-5-17
It sounds to me as if you are resetting the seed each time to the same value. That is exactly what you DON’T want to do. Either use something like rng('shuffle') or leave it alone. Read the description at:
http://www.mathworks.com/help/matlab/ref/rng.html
类别
在 帮助中心 和 File Exchange 中查找有关 Sources 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!