random selection

I have a matrix size of 96x249.How can i select 48 rows randomly and store it into a new matrix of 48x249.I have values in matrix as decimal numbers.

 Respuesta aceptada

Walter Roberson
Walter Roberson el 30 de Oct. de 2011

2 votos

T = randperm(96);
NewMatrix = OldMatrix(T(1:48),:);

2 comentarios

Abhiya
Abhiya el 1 de Nov. de 2011
thanks for the answer.do i have an option to store the rest of the matrix after random selection?
Walter Roberson
Walter Roberson el 1 de Nov. de 2011
RestOfMatrix = OldMatrix(T(49:end),:);

Iniciar sesión para comentar.

Más respuestas (2)

Peter Perkins
Peter Perkins el 1 de Nov. de 2011

1 voto

There are a number of ways to do this, including Walter's suggestion. But in addition, if you have access to MATLAB R2011b, there is the slightly simpler
NewMatrix = OldMatrix(randperm(96,48),:);
and if you have access to the Statistics Toolbox in R2011b, there is also
NewMatrix = datasample(OldMatrix,48);
The latter option also allows you to sample with weights, and with replacement. Of course, neither allows you to get the rest of the matrix.
Abhiya
Abhiya el 4 de Nov. de 2011

0 votos

My heartful thanks to everybody

Categorías

Más información sobre Creating and Concatenating Matrices en Centro de ayuda 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