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.
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)
Nice code! Thanks
Absolutely brilliant piece of code
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?
Very useful, thanks.
Exactly what is needed when finding syndromes for the corresponding bit error patterns when making a decoder for block codes
Amanda, could you contact me directly? See any of my recent submissions for an address. Jos
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!
This code is so good.
It does exactly what I was needing.
does exactly what i'm looking for. good job and thanks.
Dimitri, you're right. This is a somewhat harsh, undocumented and unnecessary restriction. I will update the file shortly.
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?