PERMPOS

all possible ordered permutations of M values in N positions
3,7K download
Aggiornato 14 mag 2019

Visualizza la licenza

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

Cita come

Jos (10584) (2024). PERMPOS (https://www.mathworks.com/matlabcentral/fileexchange/11216-permpos), MATLAB Central File Exchange. Recuperato .

Compatibilità della release di MATLAB
Creato con R2018b
Compatibile con qualsiasi release
Compatibilità della piattaforma
Windows macOS Linux
Categorie
Scopri di più su Characters and Strings in Help Center e MATLAB Answers
Riconoscimenti

Ispirato: NEXTPERMPOS

Community Treasure Hunt

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

Start Hunting!
Versione Pubblicato Note della release
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.)