How do I sample a random value from a matrix?

4 views (last 30 days)
Let's say I have a random matrix:
A = rand(10,4)
How can I sample a random value from this matrix (without replacement)? Essentially how can I perform a randsample but for a matrix instead of a vector?

Accepted Answer

Akira Agata
Akira Agata on 2 May 2018
If you want to obtain k samples randomly from A, the following will do that.
ind = randperm(numel(A),k);
output = A(ind);

More Answers (0)

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!