フィルターのクリア

select randomly "N" rows of a matrix?

10 ビュー (過去 30 日間)
Noe alvarado
Noe alvarado 2012 年 4 月 12 日
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]

採用された回答

Thomas
Thomas 2012 年 4 月 12 日
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 件のコメント
Jan
Jan 2012 年 4 月 12 日
@Noe, Then use: c = randperm(size(M, 1)); c = c(1:N);
Noe alvarado
Noe alvarado 2012 年 4 月 12 日
thanks

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeRandom Number Generation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by