how to define a random variable in matlab code?

16 visualizzazioni (ultimi 30 giorni)
MANJUNATHA
MANJUNATHA il 11 Gen 2013
how to define random variable in matlab..

Risposte (2)

Azzi Abdelmalek
Azzi Abdelmalek il 11 Gen 2013
Modificato: Azzi Abdelmalek il 11 Gen 2013
x=rand
%or
v=rand(3,4)
%or
randi(10,3,4)

Wayne King
Wayne King il 11 Gen 2013
Modificato: Wayne King il 11 Gen 2013
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.

Categorie

Scopri di più su Random Number Generation in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by