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!