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