N.B: This is not a duplication of my last question because I added constraints!
I want to generate a matrix A(40x10000) of random number between 1 and 100 with a given probability:
p1=Prob(1) (chance of 1)
p2=Prob(2) (chance of 2)
...
p100=Prob(100) (chance of 100)
and constraints: V1,V2,...,V20 are vectors containing 4 elements between 1 and 100. Each column vector of the matrix A should contain at least one element of each of these 20 vectors. V1, ..., V20
are predefined vectors with known elements.
for example, how to modify the following program to add the last constraint:
h = 40; w = 10000;
A = reshape( randsample( numel(Prob), h*w, true, Prob ), [h w] );
more details:
each
A(:,i)
{i=1,..,10000}
should containVk(1) or Vk(2) or Vk(3) or Vk(4)
for allk=1,..,20
.A(:,i)
must contain at least one value from everyVk
, but that it will respect the probabilities and does not generate duplicate values. If some values ofVi
andVj
are equal,A(:,k)
could have a single element validating bothVi
andVj
constraints.for example: if
V1=[6 87 1 56]
,A(:,i)
should contain 6 or 87 or 1 or 56 butA(:, i)
may contain (6 and 1) or (6 and 1 and 87) or ...