Function Reference: datasample

statistics: y = datasample (data, k)
statistics: y = datasample (data, k, dim)
statistics: y = datasample (…, Name, Value)
statistics: [y idcs] = datasample (…)

Randomly sample data.

Return k observations randomly sampled from data. data can be a vector or a matrix of any data. When data is a matrix or a n-dimensional array, the samples are the subarrays of size n - 1, taken along the dimension dim. The default value for dim is 1, that is the row vectors when sampling a matrix.

Output y is the returned sampled data. Optional output idcs is the vector of the indices to build y from data.

Additional options are set through pairs of parameter name and value. Available parameters are:

Replace

a logical value that can be true (default) or false: when set to true, datasample returns data sampled with replacement.

Weigths

a vector of positive numbers that sets the probability of each element. It must have the same size as data along dimension dim.

See also: rand, randi, randperm, randsample

Source Code: datasample