PARTITIONS

버전 1.1.0.0 (3.79 KB) 작성자: Matt Fig
Finds all partitions of a set, or only those partitions of a specified length. Includes a viewer.
다운로드 수: 2.9K
업데이트 날짜: 2009/5/21

라이선스 보기

C = PARTITIONS(N), for scalar N, returns all possible partitions of the set given by {1,2,3,...N}.
C = PARTITIONS(N), for vector N, returns the partitions of the vector elements, treated as members of a set.
C = PARTITIONS(N), for cell N, returns the partitions of the cell
elements treated as members of a set.

PARTITIONS(N,K) returns only the partitions of length K.
The results are stored in a cell array. For example:

The 15 partitions set {1 2 3 4}:
{1 2 3 4}
{1 2 3} {4}
{1 2 4} {3}
{1 2} {3 4}
{1 2} {3} {4}
{1 3 4} {2}
{1 3} {2 4}
{1 3} {2} {4}
{1 4} {2 3}
{1} {2 3 4}
{1} {2 3} {4}
{1 4} {2} {3}
{1} {2 4} {3}
{1} {2} {3 4}
{1} {2} {3} {4}

Also included is a viewer function, PARTDISP, which allows for easy viewing of the partitions. The output is a string to the command window.

C = partitions({'peanut','butter','yummy'});
partdisp(C)

The 5 partitions of set {peanut butter yummy}:
{peanut butter yummy}
{peanut butter} {yummy}
{peanut yummy} {butter}
{peanut} {butter yummy}
{peanut} {butter} {yummy}

Please: READ THE HELP BEFORE USING.
Please email me if bugs are found in the code.
Thanks.

인용 양식

Matt Fig (2024). PARTITIONS (https://www.mathworks.com/matlabcentral/fileexchange/24185-partitions), MATLAB Central File Exchange. 검색됨 .

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

받음: Set partition

줌: Set partition

Community Treasure Hunt

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

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

Added viewer, capability for user to specify set.

1.0.0.0