How can I generate a randomized vector of repeating numbers with given conditions?
이전 댓글 표시
I'm trying to generate a vector of pseudo-random numbers that contains 1:11 repeated 8 times. The vector is broken up into blocks of 8. No number within each block can be repeated and each number has to occur at each position within the block once (i.e the number 4 has to occur first-eighth in eight different blocks). I've gone through a ton of iterations to do this and have attached the most recent attempt. The problem here is that by the end of the loop, the only possible numbers remaining are ones that have already been added within the current block of 8 numbers, so it becomes an endless while loop. Any help would be much appreciated!
TargTest=nan(8,11);%M by N array to indicate if Nth target was tested at Mth location
TestSessionTargs=[]; %Test Session Target order
while length(TestSessionTargs)<numel(TargTest)
TestBlock=nan(1,8);
for B=1:length(TestBlock)
PossibleTargs=find(isnan(TargTest(B,:))==1);
if length(PossibleTargs)~=1
F=randsample(PossibleTargs,1);
while ismember(F,TestBlock)
F=randsample(PossibleTargs,1);
end
else
F=PossibleTargs;
end
TestBlock(B)=F
TargTest(B,F)=1;
end
TestSessionTargs=[TestSessionTargs TestBlock];
end
댓글 수: 7
Walter Roberson
2015년 5월 8일
Are the blocks "sliding" blocks? Could a 7 from one block happen to be at the end of the block, and a 7 happen to be at the beginning of the next block?
Karthik
2015년 5월 8일
Walter Roberson
2015년 5월 8일
If you have blocks of 8, but you have 11 different values 1:11, then how can each of the 11 different values occur once in each position?
Or is the idea that a pseudo-random subset of 8 of the 11 will be chosen, and after that the conditions must be filled for that subset?
Karthik
2015년 5월 8일
Karthik
2015년 5월 8일
Karthik
2015년 5월 8일
ali mokhtar
2022년 3월 28일
targtest=ntest(13:end);
what do you mean
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Sources에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!