Code covered by the BSD License  

Highlights from
PERMPOS

4.7

4.7 | 10 ratings Rate this file 21 Downloads (last 30 days) File Size: 2.12 KB File ID: #11216

PERMPOS

by

 

28 May 2006 (Updated )

all possible permutations of M values in N positions

| Watch this File

File Information
Description

PERMPOS - all possible permutations of M values in N positions
    B = PERMPOS(M,N) where M and N are non-negative integers produces a
    logical (N!/M!(N-M)!)-by-N matrix in which each row contains a unique
    permation of M trues and (N-M) falses. Note that each column will hence
    contain (N-1) trues.
    
    B = PERMPOS(V,N) where V is a vector of length M produces a matrix
    where each row a contains the values of V in preserved order, but
    uniquely permuted at the N columns. The remaining positions are zero.
 
    Examples:
      permpos(2,4) % ->
       % 1 1 0 0
       % 1 0 1 0
       % 1 0 0 1
       % 0 1 1 0
       % 0 1 0 1
       % 0 0 1 1
 
      permpos([-4 9 3],4) % >
       % -4 9 3 0
       % -4 9 0 3
       % -4 0 9 3
       % 0 -4 9 3
 
    See also NCHOOSEK, PERMS, RANDPERM, TRUE, FALSE
    and COMBN, ALLCOMB, BALLATSQ, NONES (Matlab File Exchange)

Version 2.1 (march 2007)

Acknowledgements

This file inspired Nextpermpos.

MATLAB release MATLAB 6.5 (R13)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (13)
26 Jun 2014 Manoj

Absolutely brilliant piece of code

24 Jul 2012 Jenn Lee

I'm loving this code, but when I use (16,32) it starts to stall out, is there a way that this can be parallelized so that I can run it on a remote cluster?

28 May 2012 Sam  
15 Oct 2010 Nima Moshtagh  
03 Mar 2010 Richard Crozier

Very useful, thanks.

19 Feb 2009 Anders

Exactly what is needed when finding syndromes for the corresponding bit error patterns when making a decoder for block codes

27 Oct 2008 Jos (10584)

Amanda, could you contact me directly? See any of my recent submissions for an address. Jos

27 Oct 2008 Amanda

I've been struggling with a matlab problem of combinations and permutations for a while and came across your post here. I thought you might be able to help me out.

Let's say I have a vector say A =[1 2 3 4] and want to find every way I can choose all the elements of A to fit in some number of bins (let's say 3). Bin 1 could have (1, 2, 3), Bin 2 could have (4) or (0) and Bin 3 could have (4) or (0) as well. The problem isn't quite solved by "nchoosek" or "permpos" because each bin could have more or less elements than the previous bin and the element choice for each bin depends on the elements not already chosen. I know that the number of possible combinations is # of elements in A^#of bins (in this case 81), because I solved it out by hand. I am looking for an easier way to do this! I'm sorry if this sounds confusing!

If you can point me in the right direction or offer me any help I would greatly appreciate it!

15 Apr 2008 ahmad ababnah

This code is so good.

28 Mar 2008 Berta Neto

It does exactly what I was needing.
Thanks

14 Jun 2007 brad mcevoy

does exactly what i'm looking for. good job and thanks.

05 Mar 2007 Jos (the author)

Dimitri, you're right. This is a somewhat harsh, undocumented and unnecessary restriction. I will update the file shortly.

04 Mar 2007 Dimitri Shvorob

Trying to permute a (20x1) vector:
??? Error using ==> permpos
This function is not usefull for more than 14 entries
Why impose the limit? And why not disclose it upfront?

Contact us