Thread Subject: Permutations in matlab

Subject: Permutations in matlab

From: Midhun

Date: 18 Aug, 2009 05:53:02

Message: 1 of 6

Hello,
 How can I do permutations in matlab ?

In Matalb , the command : ' combntns(set,subset)' returns a matrix whose rows are the various combinations that can be taken of the elements of the vector set of length subset.

How can I create a 'permutational' set instead of a 'combinatorial' set ?

Subject: Permutations in matlab

From: Husam Aldahiyat

Date: 18 Aug, 2009 07:23:03

Message: 2 of 6

"Midhun " <midhunjoyp@gmail.com> wrote in message <h6dfju$juk$1@fred.mathworks.com>...
> Hello,
> How can I do permutations in matlab ?
>
> In Matalb , the command : ' combntns(set,subset)' returns a matrix whose rows are the various combinations that can be taken of the elements of the vector set of length subset.
>
> How can I create a 'permutational' set instead of a 'combinatorial' set ?

I think you want perms().

Subject: Permutations in matlab

From: Midhun

Date: 18 Aug, 2009 08:53:01

Message: 3 of 6

> I think you want perms().

Thanks for your post. Infact, I was looking for a command in which I could specify the size of the subset ( not possible in ' perms(set) ' : all permutations would contain all the elements in the set. )

It is possible to do it in a roundabout way : take ' combntns(set,n) ' to get various combinations/subsets of size 'n' . For each of these rows , take perms() to get all possible permutations. Is it possible to do this using a single built-in command ?

Subject: Permutations in matlab

From: arun

Date: 18 Aug, 2009 09:24:06

Message: 4 of 6

On Aug 18, 10:53 am, "Midhun " <midhunj...@gmail.com> wrote:
> > I think you want perms().
>
> Thanks for your post. Infact, I was looking for a command in which I could specify the size of the subset ( not possible in ' perms(set) '  :  all permutations would contain all the elements in the set. )
>
> It is possible to do it in a roundabout way :  take ' combntns(set,n)  '   to get various combinations/subsets of size 'n' . For each of these rows , take perms() to get all possible permutations.  Is it possible to do this using a single built-in command ?

yes there is no direct function for permutations, as there is 1 for
combinations. Probably because its not possible to store the
permutations for n>= 11 (documentation says it takes over 3GB).

however, for small amount of numbers you could do,

a = 1:4;

acn = nchoosek(a,3);
result = arrayfun(@(x) perm(acn(x,:)), 1:length(acn), 'uni', false);
result = cat(1,result{:});

to get the permutations.

best, arun.

Subject: Permutations in matlab

From: Matt Fig

Date: 18 Aug, 2009 12:36:19

Message: 5 of 6

"Midhun " <midhunjoyp@gmail.com> wrote in message <h6dfju$juk$1@fred.mathworks.com>...
> Hello,
> How can I do permutations in matlab ?
>
> In Matalb , the command : ' combntns(set,subset)' returns a matrix whose rows are the various combinations that can be taken of the elements of the vector set of length subset.
>
> How can I create a 'permutational' set instead of a 'combinatorial' set ?


See, for example:

http://www.mathworks.com/matlabcentral/fileexchange/24325
http://www.mathworks.com/matlabcentral/fileexchange/11462

Subject: Permutations in matlab

From: Midhun

Date: 18 Aug, 2009 14:10:23

Message: 6 of 6


Thanks a lot for the post...
- Midhun

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

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.

Tag Activity for This Thread
Tag Applied By Date/Time
combntns Sprinceana 18 Aug, 2009 12:38:49
permutations Midhun 18 Aug, 2009 01:54:03
rssFeed for this Thread
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com