PERMPOS

Version 3.0.1 (2,68 ko) par Jos (10584)
all possible ordered permutations of M values in N positions
3,7K téléchargements
Mise à jour 14 mai 2019

Afficher la licence

permpos(M, N) where M and N are non-negative integers produces a
logical (N!/M!(N-M)!)-by-N matrix in which each row contains a unique
permutation of M trues and (N-M) falses.

W = permpos(V, N) where V is an array with M elements a matrix W
where each row a contains the values of V in preserved order, but
uniquely permuted at the N columns. The remaining positions are set to
NaN. W = permpos(V, N, F) uses the value F rather than NaN.

[W, B] = permpos(V, ...) also returns the logical matrix B, which is
true for the positions that are filled by elements of V. Note that B
equals "permpos(numel(V),N)".

V can be a numerical array, a cell array of chars or a string
array. F (optional) should be of the same class as V.

Examples:
permpos(2, 4)
% -> [ 1 1 0 0
% 1 0 1 0
% 1 0 0 1
% 0 1 1 0
% 0 1 0 1
% 0 0 1 1 ]

permpos(1:2:3, 4) % ->
% -> [ 1 2 3 NaN
% 1 2 NaN 3
% 1 NaN 3 3
% NaN 1 2 3 ]

permpos({'a','b'}, 3, 'XX') % filler
% -> { 'a' 'b' 'XX' ; 'a' 'XX' 'b' ; 'XX' 'a' 'b'}

See also nchoosek, perms, randperm, true, false
On the file Exchange:
permn, PERMNK, permsk, allcomb, ballatsq, nones, nextpermpos

Citation pour cette source

Jos (10584) (2024). PERMPOS (https://www.mathworks.com/matlabcentral/fileexchange/11216-permpos), MATLAB Central File Exchange. Récupéré le .

Compatibilité avec les versions de MATLAB
Créé avec R2018b
Compatible avec toutes les versions
Plateformes compatibles
Windows macOS Linux
Catégories
En savoir plus sur Characters and Strings dans Help Center et MATLAB Answers
Remerciements

A inspiré : NEXTPERMPOS

Community Treasure Hunt

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

Start Hunting!
Version Publié le Notes de version
3.0.1

new image

3.0

Implemented 2nd output and functionality for non-numeric inputs

2.4.0.0

small update

1.0.0.0

remove unnecessary check for input size (after review by Dmitri S.)