how to define a random variable in matlab code?
10 次查看(过去 30 天)
显示 更早的评论
回答(2 个)
Wayne King
2013-1-11
编辑:Wayne King
2013-1-11
That depends what you mean.
Generally what you mean is that you want some way of sampling from some probability law (distribution).
In that case, you use a random number generator to generate numbers that follow a particular distribution.
For example:
Uniform distribution on [-\pi, \pi]
x = -pi +2*pi*rand(1000,1);
hist(x)
Base MATLAB has random number generators for uniform and Gaussian random variables (randn) and random integers (randi)
The Statistics Toolbox has random number generators for a large number of common distributions.
With some ingenuity, you can use the uniform random number generator to model a large set of random variables.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Random Number Generation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!