Got Questions? Get Answers.
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:
iterative permutation

Subject: iterative permutation

From: galib

Date: 13 Sep, 2010 01:54:04

Message: 1 of 11

Hi,

I have looking in the file exchanges about something which can do iterative permutation. My problem is somewhat specific:
I have a set between 20 to 320. I have a sequence of 3 numbers between these numbers. Now, I need to locate that sequence in the combinations taking 3 numbers each time between 20 to 320.
For example:
   LH = [56 128 97];
   allcomb = all combinations from 20 to 320 taking 3 numbers each time...
I need to locate LH in allcomb.

Could you please help me.

Thanks.

Galib

Subject: iterative permutation

From: ImageAnalyst

Date: 13 Sep, 2010 02:14:13

Message: 2 of 11

Galib:
Run this little example:

 LH = [56 128 97]
 allComb = [56 128 97; 56 97 128; 128 56 97;...
     128 96 56; 97 56 128; 97 128 56]
[c rowNumber] = intersect(allComb, LH, 'rows')

 LH2 = [97 56 128]
[c rowNumber] = intersect(allComb, LH2, 'rows')

Subject: iterative permutation

From: galib

Date: 13 Sep, 2010 02:29:06

Message: 3 of 11

ImageAnalyst <imageanalyst@mailinator.com> wrote in message <79e8ed63-d592-416e-baa2-4e22d9e336c8@k11g2000vbf.googlegroups.com>...
> Galib:
> Run this little example:
>
> LH = [56 128 97]
> allComb = [56 128 97; 56 97 128; 128 56 97;...
> 128 96 56; 97 56 128; 97 128 56]
> [c rowNumber] = intersect(allComb, LH, 'rows')
>
> LH2 = [97 56 128]
> [c rowNumber] = intersect(allComb, LH2, 'rows')

Hi ImageAnalyst,

Thanks for your reply. The problem is, in my case allcomb is as follows:
allcomb = [20 20 20;20 20 21; 20 20 22; ....; 20 20 320; 20 21 20; 20 21 21;...;320 320 320]
So, I need to locate that LH in the all possible combinations of 3 numbers between 20 and 320. I have the nextperm or nextstring function from the FEX, but they generate permutations from 1 to N one by one. But I need from 20 to 320, 3 numbers at a time, 1 by 1.
Could you or anybody else please help in this regard.

Thanks.

Galib

Subject: iterative permutation

From: Ross W

Date: 13 Sep, 2010 03:13:05

Message: 4 of 11

"galib " <galib.cse@gmail.com> wrote in message <i6k29i$kjd$1@fred.mathworks.com>...
> ImageAnalyst <imageanalyst@mailinator.com> wrote in message <79e8ed63-d592-416e-baa2-4e22d9e336c8@k11g2000vbf.googlegroups.com>...
> > Galib:
> > Run this little example:
> >
> > LH = [56 128 97]
> > allComb = [56 128 97; 56 97 128; 128 56 97;...
> > 128 96 56; 97 56 128; 97 128 56]
> > [c rowNumber] = intersect(allComb, LH, 'rows')
> >
> > LH2 = [97 56 128]
> > [c rowNumber] = intersect(allComb, LH2, 'rows')
>
> Hi ImageAnalyst,
>
> Thanks for your reply. The problem is, in my case allcomb is as follows:
> allcomb = [20 20 20;20 20 21; 20 20 22; ....; 20 20 320; 20 21 20; 20 21 21;...;320 320 320]
> So, I need to locate that LH in the all possible combinations of 3 numbers between 20 and 320. I have the nextperm or nextstring function from the FEX, but they generate permutations from 1 to N one by one. But I need from 20 to 320, 3 numbers at a time, 1 by 1.
> Could you or anybody else please help in this regard.
>
> Thanks.
>
> Galib

Hi

How about NCHOOSEK? See http://www.mathworks.com/matlabcentral/fileexchange/24325-combinator-combinations-and-permutations

Ross

Subject: iterative permutation

From: galib

Date: 13 Sep, 2010 03:22:04

Message: 5 of 11

"Ross W" <rosswoodskiwi@hotmail.com> wrote in message <i6k4s1$5vg$1@fred.mathworks.com>...
> "galib " <galib.cse@gmail.com> wrote in message <i6k29i$kjd$1@fred.mathworks.com>...
> > ImageAnalyst <imageanalyst@mailinator.com> wrote in message <79e8ed63-d592-416e-baa2-4e22d9e336c8@k11g2000vbf.googlegroups.com>...
> > > Galib:
> > > Run this little example:
> > >
> > > LH = [56 128 97]
> > > allComb = [56 128 97; 56 97 128; 128 56 97;...
> > > 128 96 56; 97 56 128; 97 128 56]
> > > [c rowNumber] = intersect(allComb, LH, 'rows')
> > >
> > > LH2 = [97 56 128]
> > > [c rowNumber] = intersect(allComb, LH2, 'rows')
> >
> > Hi ImageAnalyst,
> >
> > Thanks for your reply. The problem is, in my case allcomb is as follows:
> > allcomb = [20 20 20;20 20 21; 20 20 22; ....; 20 20 320; 20 21 20; 20 21 21;...;320 320 320]
> > So, I need to locate that LH in the all possible combinations of 3 numbers between 20 and 320. I have the nextperm or nextstring function from the FEX, but they generate permutations from 1 to N one by one. But I need from 20 to 320, 3 numbers at a time, 1 by 1.
> > Could you or anybody else please help in this regard.
> >
> > Thanks.
> >
> > Galib
>
> Hi
>
> How about NCHOOSEK? See http://www.mathworks.com/matlabcentral/fileexchange/24325-combinator-combinations-and-permutations
>
> Ross

Hi Ross,

Thanks for the reply. NCHOOSEK gives you the non-repeating combinations. And also, myproblem is I am getting "out of memory" problem as I need the whole permutation set of 3 out of the 300 (from 20 to 320) numbers as I need to locate my sequence in the whole set. So...

Anyway, Thanks again. If you have any other idea, please, let me know..

Galib

Subject: iterative permutation

From: Ross W

Date: 13 Sep, 2010 03:58:03

Message: 6 of 11

"galib " <galib.cse@gmail.com> wrote in message <i6k5cs$9kd$1@fred.mathworks.com>...
> "Ross W" <rosswoodskiwi@hotmail.com> wrote in message <i6k4s1$5vg$1@fred.mathworks.com>...
> > "galib " <galib.cse@gmail.com> wrote in message <i6k29i$kjd$1@fred.mathworks.com>...
> > > ImageAnalyst <imageanalyst@mailinator.com> wrote in message <79e8ed63-d592-416e-baa2-4e22d9e336c8@k11g2000vbf.googlegroups.com>...
> > > > Galib:
> > > > Run this little example:
> > > >
> > > > LH = [56 128 97]
> > > > allComb = [56 128 97; 56 97 128; 128 56 97;...
> > > > 128 96 56; 97 56 128; 97 128 56]
> > > > [c rowNumber] = intersect(allComb, LH, 'rows')
> > > >
> > > > LH2 = [97 56 128]
> > > > [c rowNumber] = intersect(allComb, LH2, 'rows')
> > >
> > > Hi ImageAnalyst,
> > >
> > > Thanks for your reply. The problem is, in my case allcomb is as follows:
> > > allcomb = [20 20 20;20 20 21; 20 20 22; ....; 20 20 320; 20 21 20; 20 21 21;...;320 320 320]
> > > So, I need to locate that LH in the all possible combinations of 3 numbers between 20 and 320. I have the nextperm or nextstring function from the FEX, but they generate permutations from 1 to N one by one. But I need from 20 to 320, 3 numbers at a time, 1 by 1.
> > > Could you or anybody else please help in this regard.
> > >
> > > Thanks.
> > >
> > > Galib
> >
> > Hi
> >
> > How about NCHOOSEK? See http://www.mathworks.com/matlabcentral/fileexchange/24325-combinator-combinations-and-permutations
> >
> > Ross
>
> Hi Ross,
>
> Thanks for the reply. NCHOOSEK gives you the non-repeating combinations. And also, myproblem is I am getting "out of memory" problem as I need the whole permutation set of 3 out of the 300 (from 20 to 320) numbers as I need to locate my sequence in the whole set. So...
>
> Anyway, Thanks again. If you have any other idea, please, let me know..
>
> Galib

Hi

So how about VChooseKRO? It allows repetitions and all possible orders.

http://www.mathworks.com/matlabcentral/fileexchange/26242

>> tic;size(VChooseKRO(20:320, 3)),toc

ans =

    27270901 3

Elapsed time is 0.608145 seconds.

(it was slower the first time I tried, while it allocated the memory)

Ross

Subject: iterative permutation

From: galib

Date: 13 Sep, 2010 06:03:06

Message: 7 of 11

> >
> > Hi Ross,
> >
> > Thanks for the reply. NCHOOSEK gives you the non-repeating combinations. And also, myproblem is I am getting "out of memory" problem as I need the whole permutation set of 3 out of the 300 (from 20 to 320) numbers as I need to locate my sequence in the whole set. So...
> >
> > Anyway, Thanks again. If you have any other idea, please, let me know..
> >
> > Galib
>
> Hi
>
> So how about VChooseKRO? It allows repetitions and all possible orders.
>
> http://www.mathworks.com/matlabcentral/fileexchange/26242
>
> >> tic;size(VChooseKRO(20:320, 3)),toc
>
> ans =
>
> 27270901 3
>
> Elapsed time is 0.608145 seconds.
>
> (it was slower the first time I tried, while it allocated the memory)
>
> Ross

Hi Ross,

Thanks again. But my case, when I run
           tic;size(VChooseKRO(20:320, 3)),toc
it gives me "out of memory"...
My RAM is 2GB, page file is 5GB....
I don't know how exactly I can do this in groups or one-by-one.....
Anyway, thanks and please let me know if there is any other thing... :(

Galib

Subject: iterative permutation

From: Darren Rowland

Date: 13 Sep, 2010 07:09:03

Message: 8 of 11

Galib,
This is a fairly simple coding problem.

If LH is your particular permutation then the index is given by

p = 2:-1:0;
ind = sum((LH-20).*301.^p) + 1;

Hth
Darren

Subject: iterative permutation

From: galib

Date: 13 Sep, 2010 07:36:04

Message: 9 of 11

"Darren Rowland" <darrenjremovethisrowland@hotmail.com> wrote in message <i6kimf$1mr$1@fred.mathworks.com>...
> Galib,
> This is a fairly simple coding problem.
>
> If LH is your particular permutation then the index is given by
>
> p = 2:-1:0;
> ind = sum((LH-20).*301.^p) + 1;
>
> Hth
> Darren

Hi Darren,
Thank you for the reply.
Actually, just some minutes ago, I could generate the whole set of permutations by typecasting to int16 as it is less memory expensive than double. As, searching the location by using ISMEMBER function with flad 'rows' also gets "out of memory", I searched using a loop which gives me the location 3297727 where " ind = sum((LH-20).*301.^p) + 1" gives me 65806. Perhaps, I did something wrong, but anyway, if there is no easy way, then I guess, I have to go for the complex and time consuming way.

Thank you again.

Galib

Subject: iterative permutation

From: Darren Rowland

Date: 13 Sep, 2010 07:55:26

Message: 10 of 11

Galib,
My method MUST work. Check the results of these calculations.

>> sum(([20 20 20]-20).*301.^p) + 1
ans =
     1

>> sum(([20 20 21]-20).*301.^p) + 1
ans =
     2

>> sum(([20 20 320]-20).*301.^p) + 1
ans =
   301

>> sum(([20 21 20]-20).*301.^p) + 1
ans =
   302

>> sum(([20 21 320]-20).*301.^p) + 1
ans =
   602

>> sum(([320 320 320]-20).*301.^p) + 1
ans =
    27270901 % = 301^3

Subject: iterative permutation

From: galib

Date: 13 Sep, 2010 10:28:05

Message: 11 of 11

"Darren Rowland" <darrenjremovethisrowland@hotmail.com> wrote in message <i6klde$pgf$1@fred.mathworks.com>...
> Galib,
> My method MUST work. Check the results of these calculations.
>
> >> sum(([20 20 20]-20).*301.^p) + 1
> ans =
> 1
>
> >> sum(([20 20 21]-20).*301.^p) + 1
> ans =
> 2
>
> >> sum(([20 20 320]-20).*301.^p) + 1
> ans =
> 301
>
> >> sum(([20 21 20]-20).*301.^p) + 1
> ans =
> 302
>
> >> sum(([20 21 320]-20).*301.^p) + 1
> ans =
> 602
>
> >> sum(([320 320 320]-20).*301.^p) + 1
> ans =
> 27270901 % = 301^3

Hi Darren,
Yea, that actually works.. the problem was I typecasted the numbers to int16 and i think that is why, that result was given.. And now, I tried with normal double, and it is working fine.

Thank you very much. It helped me a lot..

Thanks.

Galib

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