File Exchange

image thumbnail

ALL PERMUTATIONS OF SEQUENCE

version 1.0 (1.34 KB) by

Generates All Permutations of a sequence

1 Download

Updated

View License

% Syntax
% "b = allperm(n)" Generates all permutations of Sequence [1:n].
%
% Input :
% n : Greatest Number in Sequence
%
% Output :
% b : output as cell array
%
% Example 1.
% b = allperm(2)
% b =
% {[1 2],[2 1]}
%
% Example 2.
% b = allperm(3)
% b =
% {[1 2 3],[1 3 2],[2 1 3],[2 3 1],[3 1 2],[3 2 1]}
%
% order may be different
%
% Programmed By :
% - Sandeep Solanki
% - rtm_sandeep@rediffmail.com

Comments and Ratings (4)

Stephen Cobeldick

Finding all permutations by random generation-and-checking is extremely inefficient.

Jan Simon

Jan Simon (view profile)

Jan Simon

Jan Simon (view profile)

This is an extremly inefficient implementation. It creates random permutations by the (slow) RANDPERM in an infinite loop (for i=1:inf). Then inn a FOR loop it is checked, if the perumtation is stored already. For n=10 this takes ages.
Beside Matlab's RANDPERM you find several more efficient solutions in the FEX.

Bruno Luong

Bruno Luong (view profile)

See MATLAB perms

MATLAB Release
MATLAB 7.9 (R2009b)

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Win prizes and improve your MATLAB skills

Play today