How to sort the elements of a matrix in a random order
이전 댓글 표시
I have three matrix
A=[4,5,8,1,6,3]', B =[1,2,3,7,9,6]' and C=[3,1,2,4,7,9]'
and I want to generate X=[A B C] such that each element in A,B,C is randomly placed. I amusing Matlab 2007b
댓글 수: 2
Azzi Abdelmalek
2012년 8월 28일
each element in A,B,C is randomly placed before or after concatenation?
Chimezie Umezie
2012년 8월 28일
채택된 답변
추가 답변 (3개)
Matlabbey
2012년 8월 28일
0 개 추천
maybe you could try making a new random matrix and sorting by those values.
Azzi Abdelmalek
2012년 8월 28일
편집: Azzi Abdelmalek
2012년 8월 28일
A=[4,5,8,1,6,3]', B =[1,2,3,7,9,6]', C=[3,1,2,4,7,9]'
nA=length(A);
a1=perms(1:nA);nA1=size(a1,1);
res=[A(a1(round(nA1*rand(1,1)),:)); B(a1(round(nA1*rand(1,1)),:)); C(a1(round(nA1*rand(1,1)),:))]
댓글 수: 2
Chimezie Umezie
2012년 8월 28일
편집: Chimezie Umezie
2012년 8월 28일
Azzi Abdelmalek
2012년 8월 28일
replace randi with round(nA1*rand(1,1))
Andrei Bobrov
2012년 8월 28일
abc = [A,B,C]
[~,idx] = sort(rand(size(abc)))
out = abc(sub2ind(size(abc),idx,ones(size(abc,1),1)*(1:size(abc,2))));
카테고리
도움말 센터 및 File Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!