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) |