On 3/21/2013 8:40 AM, Philippe Delaruelle wrote:
> Hi,
>
> I have the following question. I have a 192x100 matrix where the 192
> stands for the periods and the 100 for the number of appliances. I
> want to assign for each row randomly a number of 1's with the
> constraint that the total number of 1's in that row should be equal to
> an in advance declared number (lets say 8). How do I do this?
>
> Is is also possible that when an appliance (1 of the 100) has a 1 in a
> certain period (row), the next 8 periods (rows) it can't have a new 1
> assigned and thus has to be 0?
>
> Thanks in advance
> I truly hope somebody can help me..
For your first question, make a vector of 8 ones and 92 zeros, and then
use randperm:
x1 = [ones(1,8) zeros(1,92)];
x2 = x1(randperm(100))
For your second question, perhaps your ones should represent the string
'1 0 0 0 0 0 0 0 0'. But I do not know how that would help if you allow
a 1 towards the end, without so many 0s after it.
Alan Weiss
MATLAB mathematical toolbox documentation
