How do I sample a random value from a matrix?

12 vues (au cours des 30 derniers jours)
Ethan Correa
Ethan Correa le 2 Mai 2018
Commenté : Ethan Correa le 2 Mai 2018
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?

Réponse acceptée

Akira Agata
Akira Agata le 2 Mai 2018
If you want to obtain k samples randomly from A, the following will do that.
ind = randperm(numel(A),k);
output = A(ind);
  1 commentaire
Ethan Correa
Ethan Correa le 2 Mai 2018
That did the trick, thank you very much!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by