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!