Borrar filtros
Borrar filtros

select randomly "N" rows of a matrix?

10 visualizaciones (últimos 30 días)
Noe alvarado
Noe alvarado el 12 de Abr. de 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]

Respuesta aceptada

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

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Random Number Generation en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by