# Thread: Matlab matrices containing all permutations of a sequence

1. ## Matlab matrices containing all permutations of a sequence

Hello,

Is there some command in MATLAB that will give me an array of all the possible permutations of a given sequence of numbers?

For example, if I have the sequence 1,2,3, is there a command that will give me the matrix

1,2,3
1,3,2
2,1,3
2,3,1
3,1,2
3,2,1

Not necessarily in that order, but containing all 3! permutations of 1,2,3.

Thanks

2. ## Re: Matlab matrices containing all permutations of a sequence

Originally Posted by rainer
Hello,

Is there some command in MATLAB that will give me an array of all the possible permutations of a given sequence of numbers?

For example, if I have the sequence 1,2,3, is there a command that will give me the matrix

1,2,3
1,3,2
2,1,3
2,3,1
3,1,2
3,2,1

Not necessarily in that order, but containing all 3! permutations of 1,2,3.

Thanks
The >>perms<< function will do so.

CB