nchoose

버전 3.0 (2.87 KB) 작성자: Jos (10584)
all combinations of the elements of a set
다운로드 수: 3.5K
업데이트 날짜: 2019/2/8

라이선스 보기

W = nchoose(S) returns all possible combinations of 0, 1, or more
elements of the set S, having N elements. There are 2^N combinations
in total. W is a cell array and each cell holds one of these
combination (as a row vector).
S can be a cell array, and each cell of W will then contain a cell
array. W is the powerset of S, as it includes the empty set (0
elements) as it first cell.

For a vector of integers I, W = nchoose(S, I) returns only the sets
indicated by the indices I. This might be useful for large sets.

Examples:
nchoose([2 4 6 8])
% -> { [] ;
% [2] ;
% [4] ;
% [2 4] ;
% [6] ;
% ...
% [2 6 8] ;
% [4 6 8] ;
% [2 4 6 8]} ; % in total 16 different combinations

nchoose([33 22 11], [1 8 4])
% -> { [] ; [33 22 11] ; [ 33 11]}

Notes:
- For sets containing more than 18 elements a warning is given, as this
can take some time. Hit Ctrl-C to intterupt calculations.
- If S contain non-unique elements (e.g. S = [1 1 2]), nchoose will
return non-unique cells. In other words, nchoose treats all elements
of S as being unique. One could use nchoose(UNIQUE(S)) to avoid that.
- Loosely speaking, nchoose(S) collects all output of multiple calls to
NCHOOSEK(S, K) where K is looping from 1 to the number of elements of
S. The implementation of nchoose, however, does rely of a different
method and is much faster than such a loop.
- For more information, see: http://en.wikipedia.org/wiki/Power_set

See also nchoosek, perms,
permn, nchoose2, allcomb on the file Exchange

인용 양식

Jos (10584) (2024). nchoose (https://www.mathworks.com/matlabcentral/fileexchange/20011-nchoose), MATLAB Central File Exchange. 검색됨 .

MATLAB 릴리스 호환 정보
개발 환경: R2018a
모든 릴리스와 호환
플랫폼 호환성
Windows macOS Linux
카테고리
Help CenterMATLAB Answers에서 Argument Definitions에 대해 자세히 알아보기
도움

줌: nchoosecrit(S, FUN)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
버전 게시됨 릴리스 정보
3.0

implemented powers and subset

2.2.0.0

updated description
update contact info. Works on most ML releases

1.1.0.0

reference to powerset

1.0.0.0

improved algorithm (thank US!)