NEXTPERMPOS

バージョン 1.0.0.0 (2.38 KB) 作成者: Jos (10584)
the next combination of values in specific positions (extension of PERMPOS)
ダウンロード: 239
更新 2012/10/10

ライセンスの表示

This function is an extension of PERMPOS, for large cases.
A = PERMPOS(M,N) returns a matrix A in which each row contains a unique
permutation of M trues and (N-M) falses over N columns.
When the first input to PERMPOS is a vector V with M elements, each row
of A contains the M values in order, but uniquely distributed over the N
columns of A. See PERMPOS for examples.

The number of rows increases quite rapidly with increasing M and N, in
which case the use of NEXTPERMPOS may be used to avoid memory issues.

CN = NEXTPERMPOS(C) returns a single permutation permutation. The input C
is a vector with N elements, having M non-zero (or true) elements. CN
contains the next permutation of these M values over N positions.
CN has the same size as C.

Examples:
nextpermpos([1 0 0 1 0]) % -> [1 0 0 0 1]
nextpermpos([1 0 1 1 1 0 1]) % -> [1 0 1 1 0 1 1]
nextpermpos([99 0 23]) % -> [0 99 23]
isequal(nextpermpos([1 zeros(1,999) 2 0]), [1 zeros(1,1000) 2])

A = permpos(3,6)
for k = 1:size(A,1)-1
C1 = A(k,:) ;
CN = nextpermpos(C1) ;
if ~isequal(A(k+1,:),CN), disp('This should not happen.') ; end
disp(CN) ;
end

[C2, TF] = NEXTPERMPOS(C) returns a flag that is true if C2 is really the
next permutation. If C is the last possible permutation, C2 will be the
first permutation. Examples:
[c2, tf] = nextpermpos ([0 1 0]) % c2 = [0 0 1], tf = true
[c3, tf] = nextpermpos (c2) % c3 = [1 0 0], tf = false

See also permpos (matlab File Exchange), nchoosek

引用

Jos (10584) (2024). NEXTPERMPOS (https://www.mathworks.com/matlabcentral/fileexchange/38551-nextpermpos), MATLAB Central File Exchange. 取得済み .

MATLAB リリースの互換性
作成: R2011b
すべてのリリースと互換性あり
プラットフォームの互換性
Windows macOS Linux
カテゴリ
Help Center および MATLAB AnswersArithmetic Operations についてさらに検索
謝辞

ヒントを得たファイル: PERMPOS

Community Treasure Hunt

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

Start Hunting!
バージョン 公開済み リリース ノート
1.0.0.0