How can I generate three random matrices from 20 percent of the rows of a 2000 by 80 matrix, using for loop?
1 回表示 (過去 30 日間)
古いコメントを表示
採用された回答
DGM
2021 年 6 月 24 日
I don't see why a loop is necessary. Is it?
A = rand(2000,80); % test array
s = size(A,1);
nrows = round(s*0.2);
X1 = A(randperm(s,nrows),:);
X2 = A(randperm(s,nrows),:);
X3 = A(randperm(s,nrows),:);
0 件のコメント
その他の回答 (1 件)
Chunru
2021 年 6 月 24 日
a = magic(20);
for i = 1:3
idx = randperm(20, 4); % 4 is 20% of 20; for your case 2000*20%
b = a(idx, :)
end
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Creating and Concatenating Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!