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:
Permutation or combination of numbers

Subject: Permutation or combination of numbers

From: Danny

Date: 24 Jul, 2011 00:31:11

Message: 1 of 8

I'd like to have all the possible combinations of numbers, permutation(?).
If I have a vector A=[1,2,3,4], then the matrix that I want is :

1 0 0 0
2 0 0 0
3 0 0 0
4 0 0 0
1 2 0 0
1 3 0 0
1 4 0 0
1 2 3 0
1 2 4 0
1 3 4 0
2 3 4 0
1 2 3 4

Thanks for the attention.
Danny

Subject: Permutation or combination of numbers

From: dpb

Date: 24 Jul, 2011 00:40:40

Message: 2 of 8

On 7/23/2011 7:31 PM, Danny wrote:
> I'd like to have all the possible combinations of numbers, permutation(?).
> If I have a vector A=[1,2,3,4], then the matrix that I want is :
>
> 1 0 0 0
> 2 0 0 0
> 3 0 0 0
> 4 0 0 0
> 1 2 0 0
> 1 3 0 0
> 1 4 0 0
> 1 2 3 0
> 1 2 4 0
> 1 3 4 0
> 2 3 4 0
> 1 2 3 4
>
> Thanks for the attention.
> Danny

What about

2 3
2 4
3 4
???

Try,

for idx=1:4, nchoosek(1:4,idx), end

and see what you think...

--

Subject: Permutation or combination of numbers

From: Danny

Date: 24 Jul, 2011 01:00:11

Message: 3 of 8

dpb <none@non.net> wrote in message <j0fpmd$7ni$1@speranza.aioe.org>...
> On 7/23/2011 7:31 PM, Danny wrote:
> > I'd like to have all the possible combinations of numbers, permutation(?).
> > If I have a vector A=[1,2,3,4], then the matrix that I want is :
> >
> > 1 0 0 0
> > 2 0 0 0
> > 3 0 0 0
> > 4 0 0 0
> > 1 2 0 0
> > 1 3 0 0
> > 1 4 0 0
> > 1 2 3 0
> > 1 2 4 0
> > 1 3 4 0
> > 2 3 4 0
> > 1 2 3 4
> >
> > Thanks for the attention.
> > Danny
>
> What about
>
> 2 3
> 2 4
> 3 4
> ???
>
> Try,
>
> for idx=1:4, nchoosek(1:4,idx), end
>
> and see what you think...
>
> --

Thanks, I got an idea how to do it.

Subject: Permutation or combination of numbers

From: Roger Stafford

Date: 24 Jul, 2011 01:56:09

Message: 4 of 8

"Danny " <dundee.hpaek@gmail.com> wrote in message <j0fqqq$ok2$1@newscl01ah.mathworks.com>...
> Thanks, I got an idea how to do it.
- - - - - - - - -
  For the sake of completeness you should also add "0 0 0 0". You will then notice you have 2^4 different rows, which should give you a clue for another method.

Roger Stafford

Subject: Permutation or combination of numbers

From: Roger Stafford

Date: 25 Jul, 2011 19:53:07

Message: 5 of 8

"Roger Stafford" wrote in message <j0fu3p$2lp$1@newscl01ah.mathworks.com>...
> For the sake of completeness you should also add "0 0 0 0". You will then notice you have 2^4 different rows, which should give you a clue for another method.
- - - - - - - -
  What I had in mind by that hint was that you could use dec2bin to create all sixteen possible binary numbers from 0 0 0 0 to 1 1 1 1 and use these to determine which of the elements of A would be selected in each row.

 M = bsxfun(@times,A,dec2bin((0:2^4-1).',4)-'0';);

  (Admittedly these are not in the order you have given here.)

Roger Stafford

Subject: Permutation or combination of numbers

From: Danny

Date: 27 Jul, 2011 00:45:10

Message: 6 of 8

"Roger Stafford" wrote in message <j0khj3$haf$1@newscl01ah.mathworks.com>...
> "Roger Stafford" wrote in message <j0fu3p$2lp$1@newscl01ah.mathworks.com>...
> > For the sake of completeness you should also add "0 0 0 0". You will then notice you have 2^4 different rows, which should give you a clue for another method.
> - - - - - - - -
> What I had in mind by that hint was that you could use dec2bin to create all sixteen possible binary numbers from 0 0 0 0 to 1 1 1 1 and use these to determine which of the elements of A would be selected in each row.
>
> M = bsxfun(@times,A,dec2bin((0:2^4-1).',4)-'0';);
>
> (Admittedly these are not in the order you have given here.)
>
> Roger Stafford

Thanks. I'd like to have the combination in different order as follows :
1 0 0 0
1 2 0 0
1 2 3 0
1 2 3 4
1 3 0 0
1 3 4 0
1 4 0 0
2 0 0 0
2 3 0 0
2 3 4 0
3 0 0 0
3 4 0 0
4 0 0 0

Subject: Permutation or combination of numbers

From: Roger Stafford

Date: 27 Jul, 2011 03:09:08

Message: 7 of 8

"Danny " <dundee.hpaek@gmail.com> wrote in message <j0nn2m$41s$1@newscl01ah.mathworks.com>...
> Thanks. I'd like to have the combination in different order as follows :
> 1 0 0 0
> 1 2 0 0
> 1 2 3 0
> 1 2 3 4
> 1 3 0 0
> 1 3 4 0
> 1 4 0 0
> 2 0 0 0
> 2 3 0 0
> 2 3 4 0
> 3 0 0 0
> 3 4 0 0
> 4 0 0 0
- - - - - - - - - -
  What is the criterion behind your selection here, Danny? This is different from the one you presented earlier in this thread. You have added 2 3 0 0 and 3 4 0 0 but have dropped 1 2 4 0. You have also changed the order in their sequence. I assume you have some underlying and specific scheme that would apply to any number of elements in A, but it isn't clear to me what that might be. I could make some guesses but I would much prefer for you to give it to us directly and unambiguously.

Roger Stafford

Subject: Permutation or combination of numbers

From: Danny

Date: 27 Jul, 2011 03:51:09

Message: 8 of 8

"Roger Stafford" wrote in message <j0nvgk$lot$1@newscl01ah.mathworks.com>...
> "Danny " <dundee.hpaek@gmail.com> wrote in message <j0nn2m$41s$1@newscl01ah.mathworks.com>...
> > Thanks. I'd like to have the combination in different order as follows :
> > 1 0 0 0
> > 1 2 0 0
> > 1 2 3 0
> > 1 2 3 4
> > 1 3 0 0
> > 1 3 4 0
> > 1 4 0 0
> > 2 0 0 0
> > 2 3 0 0
> > 2 3 4 0
> > 3 0 0 0
> > 3 4 0 0
> > 4 0 0 0
> - - - - - - - - - -
> What is the criterion behind your selection here, Danny? This is different from the one you presented earlier in this thread. You have added 2 3 0 0 and 3 4 0 0 but have dropped 1 2 4 0. You have also changed the order in their sequence. I assume you have some underlying and specific scheme that would apply to any number of elements in A, but it isn't clear to me what that might be. I could make some guesses but I would much prefer for you to give it to us directly and unambiguously.
>
> Roger Stafford

Thanks, Roger.
I omitted 1 2 4 0 as you indicated.
I intended to run for loop with all combination in the previous order but I realized that the combinations are huge and impossible to calculate it only if N >10.
In reality, N >50 and I'd like to group the combinations with first two digit and if those are not satisfied, the sub-comb. will be ignored.

1 0 0 0
-----------
1 2 0 0
1 2 3 0
1 2 3 4
1 2 4 0
-----------
1 3 0 0
1 3 4 0
-----------
1 4 0 0
-----------
2 0 0 0
2 3 0 0
2 3 4 0

... ...

Tags for 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