Products & Services Industries Academia Support User Community Company

Learn more about Statistics Toolbox   

randsample - Random sample

Syntax

y = randsample(n,k)
y = randsample(population,k)
y = randsample(...,replace)
y = randsample(...,true,w)
y = randsample(s, ...)

Description

y = randsample(n,k) returns a k-by-1 vector y of values sampled uniformly at random, without replacement, from the integers 1 to n.

y = randsample(population,k), where population is a vector of two or more values, returns a vector of values sampled uniformly at random, without replacement, from the values in the vector population. The orientation of y (row or column) is the same as population.

y = randsample(...,replace) returns a sample taken with replacement if replace is true, or without replacement if replace is false. The default is false.

y = randsample(...,true,w) returns a weighted sample taken with replacement, using a vector of positive weights w, whose length is n. The probability that the integer i is selected for an entry of y is w(i)/sum(w). Usually, w is a vector of probabilities. randsample does not support weighted sampling without replacement.

y = randsample(s, ...) uses the stream s for random number generation. s is a member of the RandStream class. Default is the MATLAB default random number stream.

Examples

The following command generates a random sequence of the characters A, C, G, and T, with replacement, according to the specified probabilities.

R = randsample('ACGT',48,true,[0.15 0.35 0.35 0.15])

See Also

rand, randperm

  


Recommended Products

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.

 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS