How to divide a vector randomly in 3 groups?
이전 댓글 표시
Hello everyone,
I have the following problem: I have a column vector A = [1:1000]' and I would like to divide it in 3 groups randomly. (For example in A1=[1:200], A2=[1:450], A3=[1:350]) It doesn't matter if the groups are contiguous. That is, if the first group is made up of sample 1 to 200, the second group should be made up of sample 201 to 650, etc.
The only requirement is that each group must contain at least 10% to 80% of the data. That is, there cannot be a group with 2 samples and the rest with 499 and 499.
Thanks in advance,
J.F.
댓글 수: 2
James Tursa
2021년 2월 19일
Each group contains 10% to 80% of the data, and you allow overlaps?
Javier Fuster
2021년 2월 20일
채택된 답변
추가 답변 (1개)
James Tursa
2021년 2월 20일
Maybe a simple loop:
n = numel(A);
n10 = floor(0.10*n)-1;
n80 = floor(0.80*n);
for k=1:3
k1 = randi(n-n10);
k2 = k1 + n10 + randi(min(n-n10-k1+1,n80-n10)) - 1;
G{k} = A(k1:k2);
end
댓글 수: 6
Javier Fuster
2021년 2월 20일
James Tursa
2021년 2월 20일
I thought you wrote that overlaps were OK. And what do you mean by samples not being "grouped"?
Javier Fuster
2021년 2월 20일
James Tursa
2021년 2월 20일
편집: James Tursa
2021년 2월 20일
Well, now it sounds like you want complete coverage of your sample set. This doesn't seem to match the A1=[1:200], A2=[1:450], A3=[1:350] example you originally posted where the apparent indexing all started at 1. But maybe what you meant to convey is just the number of elements in each group, not the indexing. True?
Javier Fuster
2021년 2월 20일
Javier Fuster
2021년 2월 22일
카테고리
도움말 센터 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


