File Exchange

image thumbnail

Stratified matrix sampling

version 1.0.0 (1.77 KB) by Jan Motl
Random matrix sampling, which is stratified by rows and columns


Updated 09 Jul 2019

View License

We can easily sample a matrix with rand() function. However, this sampling is sometimes too random - we may end up with rows or columns without any sample and "screw" the downstream code. The canonical solution to this problem is to use stratified sampling. This function implements stratification by both, rows and columns, for a rectangular matrix.

The sampling is without replacement (each field in the matrix can be selected at most once). And we have to provide the count of samples that we want to select.

The function does not use rejection sampling and is reasonably fast (~twice as slow as rand()).

Cite As

Jan Motl (2020). Stratified matrix sampling (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (0)

MATLAB Release Compatibility
Created with R2018a
Compatible with any release
Platform Compatibility
Windows macOS Linux
Tags Add Tags