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