Filter löschen
Filter löschen

select randomly "N" rows of a matrix?

10 Ansichten (letzte 30 Tage)
Noe alvarado
Noe alvarado am 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]

Akzeptierte Antwort

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

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Random Number Generation finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by