Effacer les filtres
Effacer les filtres

select randomly "N" rows of a matrix?

10 vues (au cours des 30 derniers jours)
Noe alvarado
Noe alvarado le 12 Avr 2012
how i can select randomly "N" rows of a matrix? for example
M =
[ a12, a12]
[ a21, a22]
[ a31, a32]
[ a41, a42]
For N=2
B =
[ a12, a12]
[ a31, a32]
[ a21, a22]

Réponse acceptée

Thomas
Thomas le 12 Avr 2012
try:
N=2; % no. of rows needed
M=rand(5) % generate a 5x5 matrix random
c=randperm(length(M),N)
B=M(c,:) % output matrix
  4 commentaires
Jan
Jan le 12 Avr 2012
@Noe, Then use: c = randperm(size(M, 1)); c = c(1:N);
Noe alvarado
Noe alvarado le 12 Avr 2012
thanks

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Random Number Generation dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by