Well, this may seem like a strange question, but carry me.
So, I have a random vector in a .m file with certain limitations built into it. Here is my code:
randvecall = randsample(done, done, true); randvec = randvecall([1;diff(randvecall(:))]~=0);
Done is just a range of values from which we take a sample, so don't worry about it. As you can see, this changes the range of values and then cuts out this random vector using the diff function, so that duplicate duplicate values are removed. There is still potential for repeating values in a vector, but they simply cannot be sequential.
It is good and good, and works great.
So let's say randvec looks like this:
randvec = 54 47 52 26 39 2 14 51 24 6 19 56 34 46 12 7 41 18 29 7
Actually it is much longer, with something like 60-70 values, but you get the point.
I want to add a little extra restriction on this vector. When I take a sample from this vector, the values are classified according to their range. Thus, values from 1-15 belong to category 1, 16-30 belong to category 2, etc. The reasons for this are not significant, but this is a rather important part of the program. Therefore, if you look at the above values, you will see a section like this:
7 41 18 29 7
This is really bad for my program. Since the ranges of values are processed separately, 41, 18 and 29 are used in different ways than 7. So, for all purposes and tasks, 7 appears sequentially in my script. What I want to do is somehow parse / modify / regardless of the vector when it is generated so that the same number from a certain range does not appear twice "in a row", no matter how many other numbers from different ranges located between them. Does this make sense / have I described it well? So, I want MATLAB to search for a vector, and for all values in certain ranges (1-15,16-30,31-45,46-60) make sure that the "consecutive" values from the same range are not identical.
So here is what I want to do. This in no way may be the best way to do this, so any tips / alternatives are certainly appreciated. I know that I can do it better with multiple vectors, but for various reasons I need it to be one long vector (as my script project was designed, it just wouldn't work if I had a separate vector for each range values).