MATLAB: How to sort a vector in a random manner in MATLAB

MATLABrandomsort

I have a 1-dimensional array and would like to sort the elements of this vector randomly.

Best Answer

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)));