Mercurial > hg > camir-ismir2012
annotate toolboxes/FullBNT-1.0.7/KPMtools/nchoose2.m @ 0:cc4b1211e677 tip
initial commit to HG from
Changeset:
646 (e263d8a21543) added further path and more save "camirversion.m"
author | Daniel Wolff |
---|---|
date | Fri, 19 Aug 2016 13:07:06 +0200 |
parents | |
children |
rev | line source |
---|---|
Daniel@0 | 1 function c = nchoose2(v, f) |
Daniel@0 | 2 %NCHOOSE2 All combinations of N elements taken two at a time. |
Daniel@0 | 3 % |
Daniel@0 | 4 % NCHOOSE2(1:N) or NCHOOSEK(V) where V is a vector of length N, |
Daniel@0 | 5 % produces a matrix with N*(N-1)/2 rows and K columns. Each row of |
Daniel@0 | 6 % the result has K of the elements in the vector V. |
Daniel@0 | 7 % |
Daniel@0 | 8 % NCHOOSE2(N,FLAG) is the same as NCHOOSE2(1:N) but faster. |
Daniel@0 | 9 % |
Daniel@0 | 10 % NCHOOSE2(V) is much faster than NCHOOSEK(V,2). |
Daniel@0 | 11 % |
Daniel@0 | 12 % See also NCHOOSEK, PERMS. |
Daniel@0 | 13 |
Daniel@0 | 14 % Author: Peter J. Acklam |
Daniel@0 | 15 % Time-stamp: 2000-03-03 13:03:59 |
Daniel@0 | 16 % E-mail: jacklam@math.uio.no |
Daniel@0 | 17 % URL: http://www.math.uio.no/~jacklam |
Daniel@0 | 18 |
Daniel@0 | 19 nargs = nargin; |
Daniel@0 | 20 if nargs < 1 |
Daniel@0 | 21 error('Not enough input arguments.'); |
Daniel@0 | 22 elseif nargs == 1 |
Daniel@0 | 23 v = v(:); |
Daniel@0 | 24 n = length(v); |
Daniel@0 | 25 elseif nargs == 2 |
Daniel@0 | 26 n = v; |
Daniel@0 | 27 else |
Daniel@0 | 28 error('Too many input arguments.'); |
Daniel@0 | 29 end |
Daniel@0 | 30 |
Daniel@0 | 31 [ c(:,2), c(:,1) ] = find( tril( ones(n), -1 ) ); |
Daniel@0 | 32 |
Daniel@0 | 33 if nargs == 1 |
Daniel@0 | 34 c = v(c); |
Daniel@0 | 35 end |