How can I sort a vector in a random manner in MATLAB?

77 Ansichten (letzte 30 Tage)
I have a 1-dimensional array and would like to sort the elements of this vector randomly.

Akzeptierte Antwort

MathWorks Support Team
MathWorks Support Team am 29 Jun. 2011
To sort the elements of a vector randomly you can use the RANDPERM() function.
RANDPERM(n) returns a random permutation of the integers 1:n.
a = [1 2 3 4 5];
a_rand = a(randperm(length(a)));
  2 Kommentare
Dyuman Joshi
Dyuman Joshi am 25 Nov. 2020
Bearbeitet: Dyuman Joshi am 25 Nov. 2020
How to obtain all possible random permutations of an given array?
Dyuman Joshi
Dyuman Joshi am 25 Nov. 2020
Never mind, Found it. Its the perms() function.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Shifting and Sorting Matrices finden Sie in Help Center und File Exchange

Tags

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by