MATLAB Answers

generating sequence of given numbers

2 views (last 30 days)
Given an array A
A=[0 1 2]
How can I generate different sequence of number in that array like below;
A=[0 2 1]
A=[1 0 2]
A=[2 0 1]
A=[1 2 0]
A=[2 1 0]

  0 Comments

Sign in to comment.

Accepted Answer

Stephen Cobeldick
Stephen Cobeldick on 24 Feb 2019
Edited: Stephen Cobeldick on 24 Feb 2019
>> A = [0,1,2];
>> M = perms(A)
M =
2 1 0
2 0 1
1 2 0
1 0 2
0 1 2
0 2 1
And if you really want to remove that row from the output:
>> M = setdiff(perms(A),A,'rows')
M =
0 2 1
1 0 2
1 2 0
2 0 1
2 1 0

  1 Comment

Sign in to comment.

More Answers (0)


Translated by