comparison toolboxes/FullBNT-1.0.7/KPMtools/nchoose2.m @ 0:e9a9cd732c1e tip

first hg version after svn
author wolffd
date Tue, 10 Feb 2015 15:05:51 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:e9a9cd732c1e
1 function c = nchoose2(v, f)
2 %NCHOOSE2 All combinations of N elements taken two at a time.
3 %
4 % NCHOOSE2(1:N) or NCHOOSEK(V) where V is a vector of length N,
5 % produces a matrix with N*(N-1)/2 rows and K columns. Each row of
6 % the result has K of the elements in the vector V.
7 %
8 % NCHOOSE2(N,FLAG) is the same as NCHOOSE2(1:N) but faster.
9 %
10 % NCHOOSE2(V) is much faster than NCHOOSEK(V,2).
11 %
12 % See also NCHOOSEK, PERMS.
13
14 % Author: Peter J. Acklam
15 % Time-stamp: 2000-03-03 13:03:59
16 % E-mail: jacklam@math.uio.no
17 % URL: http://www.math.uio.no/~jacklam
18
19 nargs = nargin;
20 if nargs < 1
21 error('Not enough input arguments.');
22 elseif nargs == 1
23 v = v(:);
24 n = length(v);
25 elseif nargs == 2
26 n = v;
27 else
28 error('Too many input arguments.');
29 end
30
31 [ c(:,2), c(:,1) ] = find( tril( ones(n), -1 ) );
32
33 if nargs == 1
34 c = v(c);
35 end