I'd argue that requiring that the outliers/deviants NOT be consecutive biases your results.
But this is easy enough to do.
Start by deciding how many deviants you need. In the example, you had 29 of them.
Now, insert one standard tones between every deviant. That insures you will not have anything consecutive. You may decide to insert a standard tone before the first, and after the last. I chose that as the desired behavior.
Finally, you now have a total of 29 + 30 tones in place. You want a total of 114 tones, so you need to choose random places to insert new tones. There are several ways you can do that, but even if you just pick a random spot one at a time, who cares? There will be only 114 - 59 = 55 new tones to insert. The code I wrote below is fully vectorized however.
In the example I'll give, the final result will have a 1 in it, where a deviant tone will live. There will ALWAYS be at least one standard tone between every deviant tone. (Even though I disagree with that. Your experiment however, so your choice.)
ndev = 29;
ntot = 114;
seq = zeros(1,ndev*2 + 1);
seq(2:2:end) = 1;
seqfinal = zeros(1,ntot);
seqfinal(sort(randperm(ntot,ndev*2 + 1))) = seq;
So the final sequence chosen is:
seqfinal =
Columns 1 through 21
0 1 0 0 1 0 0 0 0 1 0 1 0 0 0 0 1 0 0 0 1
Columns 22 through 42
0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0
Columns 43 through 63
0 1 0 0 0 0 0 0 0 0 1 0 1 0 1 0 0 0 0 0 1
Columns 64 through 84
0 0 0 0 1 0 0 1 0 0 1 0 0 0 0 1 0 0 1 0 1
Columns 85 through 105
0 0 0 0 0 1 0 0 0 0 1 0 1 0 0 1 0 0 0 1 0
Columns 106 through 114
1 0 0 1 0 1 0 1 0
There are exactly 29 ones in the vector, with no pair of consecutuve ones. I set it up so that the first and last point are not 1, but that behavior could easily be changed.
Best Answer