How can I generate a vector of 19 numbers in such a way that all 19 numbers are repeated 10 times, but 10 consecutive numbers are not equal?
古いコメントを表示
So far, the code I have is this:
nTargs = 19;
pairs = nchoosek(1:nTargs, 10);
nPairs = size(pairs, 1);
order = randperm(nPairs);
values=randsample(order,19);
targs=pairs(values,:);
Alltargs=false;
while ~Alltargs
targs=pairs(randsample(order,19),:);
B=[];
for i=1:19
G=length(find(targs==i))==10;
B=[B G];
end
if sum(B)==19
Alltargs=true;
end
end
The computation time was a huge issue, there has to be a nicer way to do this. I also thought about generating all of the values and then doing some sort of rearrangement, but that was not fruitful. Code for that is below
N=[];
for i=1:10
N=[N randperm(19)];
end
B=[];
for j=1:19
if length(unique(N(j*10-9:j*10)))<10
B=[B 1];
end
end
B
Thanks for any input.
2 件のコメント
Walter Roberson
2014 年 2 月 4 日
編集済み: Walter Roberson
2014 年 2 月 4 日
When you say "but 10 consecutive numbers are not equal", do you mean that no sequence of 10 digits is exactly the same as any other sequence of 10 digits, or do you mean that in every sequence of 10 digits, no digit is repeated?
Karthik
2014 年 2 月 4 日
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Shifting and Sorting Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!