allcomb(varargin)

버전 4.2.0.0 (4.43 KB) 작성자: Jos (10584)
All combinations of input (v4.2, apr 2018)
다운로드 수: 25K
업데이트 날짜: 2018/4/30

라이선스 보기

편집자 메모: This file was a File Exchange Pick of the Week

ALLCOMB - All combinations
B = ALLCOMB(A1,A2,A3,...,AN) returns all combinations of the elements
in the arrays A1, A2, ..., and AN. B is P-by-N matrix, where P is the product
of the number of elements of the N inputs. This functionality is also
known as the Cartesian Product. The arguments can be numerical and/or
characters, or they can be cell arrays.

Examples:
allcomb([1 3 5],[-3 8],[0 1]) % numerical input:
% -> [ 1 -3 0
% 1 -3 1
% 1 8 0
% ...
% 5 -3 1
% 5 8 1 ] ; % a 12-by-3 array

allcomb('abc','XY') % character arrays
% -> [ aX ; aY ; bX ; bY ; cX ; cY] % a 6-by-2 character array

allcomb('xy',[65 66]) % a combination
% -> ['xA' ; 'xB' ; 'yA' ; 'yB'] % a 4-by-2 character array

allcomb({'hello','Bye'},{'Joe', 10:12},{99999 []}) % all cell arrays
% -> { 'hello' 'Joe' [99999]
% 'hello' 'Joe' []
% 'hello' [1x3 double] [99999]
% 'hello' [1x3 double] []
% 'Bye' 'Joe' [99999]
% 'Bye' 'Joe' []
% 'Bye' [1x3 double] [99999]
% 'Bye' [1x3 double] [] } ; % a 8-by-3 cell array

ALLCOMB(..., 'matlab') causes the first column to change fastest which
is consistent with matlab indexing. Example:
allcomb(1:2,3:4,5:6,'matlab')
% -> [ 1 3 5 ; 1 4 5 ; 1 3 6 ; ... ; 2 4 6 ]

If one of the arguments is empty, ALLCOMB returns a 0-by-N empty array.

See also nchoosek, perms, ndgrid
and nchoose, combn, kthcombn (matlab Central FEX)

인용 양식

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

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

Community Treasure Hunt

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

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

fixed some grammar mistakes

4.1.0.0

fixed error noted by Richard

1.6.0.0

v4.0 accepts cell arrays as input

1.5.0.0

now accepts character arrays

1.4.0.0

remove superfluous line of code (thanks to Edward)

1.3.0.0

(2.1, feb 2011) - fixed the check of the last argument when the last argument was neither a char or a double.

1.2.0.0

Convinced by Bruno, I decided to change the behavior when an input is empty (now returns empty instead of ignoring the input).

1.1.0.0

little speed improvement as suggested by Jan Simon

1.0.0.0

1) Removed a erroneous warning when no empty inputs were _not_ provided.
2) Added the option to let the first input run fastest (thanks to John D'Errico)