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

70 visualizaciones (últimos 30 días)
I have a 1-dimensional array and would like to sort the elements of this vector randomly.

Respuesta aceptada

MathWorks Support Team
MathWorks Support Team el 29 de Jun. de 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 comentarios
Dyuman Joshi
Dyuman Joshi el 25 de Nov. de 2020
Editada: Dyuman Joshi el 25 de Nov. de 2020
How to obtain all possible random permutations of an given array?
Dyuman Joshi
Dyuman Joshi el 25 de Nov. de 2020
Never mind, Found it. Its the perms() function.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Shifting and Sorting Matrices en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by