FUNCTION REFERENCE

datasample

Sample rows, columns or vector elements while preserving class.

Sample rows, columns or vector elements while preserving class.

Syntax

[y,idx] = datasample(data,k[,dim][,'Replace',replacement,'Weights',weights])

Replace defaults to true. dim defaults to the first nonsingleton dimension; 1 samples rows and 2 columns. idx contains one-based selected indices. Numeric, logical, char, cell and string arrays are accepted. Zero weights are never selected.

Example

rng(7); [y,idx] = datasample([1 2;3 4;5 6],2,'Replace',false)

Differences from MATLAB: 2-D data only; weighted sampling without replacement uses Efraimidis-Spirakis keys with the same sampling distribution and different draws. Samples differ even after rng(seed); only rand, randn and randi match its stream. RandStream inputs are not supported yet.

These are the engine’s help pages. Each page keeps its compatibility notes. File operations are unavailable in the browser.