2.0

2.0 | 1 rating Rate this file 15 Downloads (last 30 days) File Size: 1.34 KB File ID: #37558

ALL PERMUTATIONS OF SEQUENCE

by

 

Generates All Permutations of a sequence

| Watch this File

File Information
Description

% 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

MATLAB release MATLAB 7.9 (R2009b)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (3)
19 Jul 2012 Jan Simon  
19 Jul 2012 Jan Simon

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.

19 Jul 2012 Bruno Luong

See MATLAB perms

Contact us