Azzera filtri
Azzera filtri

select randomly "N" rows of a matrix?

10 visualizzazioni (ultimi 30 giorni)
Noe alvarado
Noe alvarado il 12 Apr 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]

Risposta accettata

Thomas
Thomas il 12 Apr 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 Commenti
Jan
Jan il 12 Apr 2012
@Noe, Then use: c = randperm(size(M, 1)); c = c(1:N);

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Random Number Generation in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by