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

조회 수: 70 (최근 30일)
MathWorks Support Team
MathWorks Support Team 2011년 6월 29일
편집: Dyuman Joshi 2020년 11월 25일
I have a 1-dimensional array and would like to sort the elements of this vector randomly.

채택된 답변

MathWorks Support Team
MathWorks Support Team 2011년 6월 29일
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
Dyuman Joshi
Dyuman Joshi 2020년 11월 25일
편집: Dyuman Joshi 2020년 11월 25일
How to obtain all possible random permutations of an given array?
Dyuman Joshi
Dyuman Joshi 2020년 11월 25일
Never mind, Found it. Its the perms() function.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by