How can I prevent to some specific numberS to be consecutive in a random matrix in MATLAB?

2 次查看(过去 30 天)
I want to create a random sequence for numbers howver some numbers should not come before or after some others.
For example after the numbers of 1,6,11,16; the some others like 1,2,3,4,5 should not come. If they came consequently ı want to shuffle the matix e until the condition is fulfilled. The same rules must be applies for more 3 groups of numbers: 2,7,12,17=>6,7,8,9,10 should not come 3,8,13,18=>11,12,13,14,15 should not come 4,9,14,19=>16,17,18,19,20 should not come
for x=1:1000
i=1:71
a = [1 5 7 10 13 15 19 20]%congruent and neutral items multiplied by 6
b = Shuffle(repmat(a,1,6))
c = [2 3 4 6 8 9 11 12 14 16 17 18 ]%incongruent items multiplied by 2
d = Shuffle(repmat(c,1,2))
e = [b d]%together
if (e(i)==1|6|11|16)&(e(i+1)~=1|2|3|4|5)
break
else
Shuffle(e)
end
x = x + 1
if x==1000
break
end
end

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Linear Algebra 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by