Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Simple problem

Subject: Simple problem

From: Iyad

Date: 20 Aug, 2013 22:06:05

Message: 1 of 8

Hey,
I have one question please:
I have an array, let say [1,2,....T], and K person. Each person must selects N elements from the array. (the elements selected by a specific person musn't be selected by an other person)
I thinked about this program

for k=1:K
    x(k)=randperm(T,N)
end

but in this solution a player can select an element already selected by an other one.
Anyone has a solution?
Thank you..

Subject: Simple problem

From: IceHaven

Date: 20 Aug, 2013 22:42:11

Message: 2 of 8

"Iyad" wrote in message <kv0p8d$i0m$1@newscl01ah.mathworks.com>...
> Hey,
> I have one question please:
> I have an array, let say [1,2,....T], and K person. Each person must selects N elements from the array. (the elements selected by a specific person musn't be selected by an other person)
> I thinked about this program
>
> for k=1:K
> x(k)=randperm(T,N)
> end
>
> but in this solution a player can select an element already selected by an other one.
> Anyone has a solution?
> Thank you..

you could remove the chosen numbers after each iteration.

for k = 1:K
x(k) = randperm(T,N)
T(T==x(k)) = [];
end

For this to work, T has to be an int array and not a float array.

Subject: Simple problem

From: Roger Stafford

Date: 20 Aug, 2013 22:49:22

Message: 3 of 8

"Iyad" wrote in message <kv0p8d$i0m$1@newscl01ah.mathworks.com>...
> I have an array, let say [1,2,....T], and K person. Each person must selects N elements from the array. (the elements selected by a specific person musn't be selected by an other person)
- - - - - - - - -
 c = nchoosek([1,2,....T],N);
 x = c(randperm(size(c,1),K),:);

Roger Stafford

Subject: Simple problem

From: Steven_Lord

Date: 20 Aug, 2013 23:19:06

Message: 4 of 8



"Iyad " <iyad.lahsen-cherif@supelec.fr> wrote in message
news:kv0p8d$i0m$1@newscl01ah.mathworks.com...
> Hey, I have one question please:
> I have an array, let say [1,2,....T], and K person. Each person must
> selects N elements from the array. (the elements selected by a specific
> person musn't be selected by an other person)

Assuming T >= K*N:

% For example
T = 52;
K = 6;
N = 5;

% Shuffle all the elements
shuffledElements = randperm(T);

% Choose only K*N of the shuffled elements
deck = shuffledElements(1:(K*N));

% Lay the deck out in a tableau
hands = reshape(deck, K, N);

Each person gets the elements listed in one of the rows of hands.

> I thinked about this program
> for k=1:K
> x(k)=randperm(T,N)

*snip*

You can't fit N elements (from the RANDPERM call) into one element of K
unless N is equal to 1.

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: Simple problem

From: Roger Stafford

Date: 20 Aug, 2013 23:43:09

Message: 5 of 8

"Iyad" wrote in message <kv0p8d$i0m$1@newscl01ah.mathworks.com>...
> (the elements selected by a specific person musn't be selected by an other person)
- - - - - - - - -
  In answering your question I interpreted your sentence "the elements selected by a specific person musn't be selected by an other person" to mean that no two people could select the same *subset* of elements. This is as opposed to the interpretation that they could not select even an element in common. Was my assumption right or was it wrong?

Roger Stafford

Subject: Simple problem

From: Iyad

Date: 21 Aug, 2013 17:02:08

Message: 6 of 8

"IceHaven" wrote in message <kv0rc2$jc8$1@newscl01ah.mathworks.com>...
> "Iyad" wrote in message <kv0p8d$i0m$1@newscl01ah.mathworks.com>...
> > Hey,
> > I have one question please:
> > I have an array, let say [1,2,....T], and K person. Each person must selects N elements from the array. (the elements selected by a specific person musn't be selected by an other person)
> > I thinked about this program
> >
> > for k=1:K
> > x(k)=randperm(T,N)
> > end
> >
> > but in this solution a player can select an element already selected by an other one.
> > Anyone has a solution?
> > Thank you..
>
> you could remove the chosen numbers after each iteration.
>
> for k = 1:K
> x(k) = randperm(T,N)
> T(T==x(k)) = [];
> end
>
> For this to work, T has to be an int array and not a float array.

Yes, the idea is to remove the chosen numbers after each iteration,
but when a test T==x(k) there is an Error using ==
(Matrix dimensions must agree.)

 

Subject: Simple problem

From: Iyad

Date: 21 Aug, 2013 18:03:11

Message: 7 of 8

"IceHaven" wrote in message <kv0rc2$jc8$1@newscl01ah.mathworks.com>...
> "Iyad" wrote in message <kv0p8d$i0m$1@newscl01ah.mathworks.com>...
> > Hey,
> > I have one question please:
> > I have an array, let say [1,2,....T], and K person. Each person must selects N elements from the array. (the elements selected by a specific person musn't be selected by an other person)
> > I thinked about this program
> >
> > for k=1:K
> > x(k)=randperm(T,N)
> > end
> >
> > but in this solution a player can select an element already selected by an other one.
> > Anyone has a solution?
> > Thank you..
>
> you could remove the chosen numbers after each iteration.
>
> for k = 1:K
> x(k) = randperm(T,N)
> T(T==x(k)) = [];
> end
>
> For this to work, T has to be an int array and not a float array.

Hey,
i proposed this solution, it seems ok

for k = 1:K
    x(k) = randperm(T,N)
    A=x(k)
    for i=1:N
         T(A(i)==x(k)) = [];
    end
end

Subject: Simple problem

From: Iyad

Date: 21 Aug, 2013 18:03:12

Message: 8 of 8

"IceHaven" wrote in message <kv0rc2$jc8$1@newscl01ah.mathworks.com>...
> "Iyad" wrote in message <kv0p8d$i0m$1@newscl01ah.mathworks.com>...
> > Hey,
> > I have one question please:
> > I have an array, let say [1,2,....T], and K person. Each person must selects N elements from the array. (the elements selected by a specific person musn't be selected by an other person)
> > I thinked about this program
> >
> > for k=1:K
> > x(k)=randperm(T,N)
> > end
> >
> > but in this solution a player can select an element already selected by an other one.
> > Anyone has a solution?
> > Thank you..
>
> you could remove the chosen numbers after each iteration.
>
> for k = 1:K
> x(k) = randperm(T,N)
> T(T==x(k)) = [];
> end
>
> For this to work, T has to be an int array and not a float array.

what do you think?

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us