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.

 채택된 답변

Walter Roberson
Walter Roberson 2011년 10월 30일

2 개 추천

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

댓글 수: 2

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

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Peter Perkins
Peter Perkins 2011년 11월 1일

1 개 추천

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 2011년 11월 4일

0 개 추천

My heartful thanks to everybody

카테고리

도움말 센터 및 File Exchange에서 Random Number Generation에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by