generating sequence of given numbers

1 vue (au cours des 30 derniers jours)
fyza affandi
fyza affandi le 24 Fév 2019
Commenté : fyza affandi le 24 Fév 2019
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]

Réponse acceptée

Stephen23
Stephen23 le 24 Fév 2019
Modifié(e) : Stephen23 le 24 Fév 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 commentaire
fyza affandi
fyza affandi le 24 Fév 2019
Thank you very much :)

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Multidimensional Arrays dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by