How to sort the elements of a matrix in a random order
Mostra commenti meno recenti
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 Commenti
Azzi Abdelmalek
il 28 Ago 2012
each element in A,B,C is randomly placed before or after concatenation?
Chimezie Umezie
il 28 Ago 2012
Risposta accettata
Più risposte (3)
Matlabbey
il 28 Ago 2012
0 voti
maybe you could try making a new random matrix and sorting by those values.
Azzi Abdelmalek
il 28 Ago 2012
Modificato: Azzi Abdelmalek
il 28 Ago 2012
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 Commenti
Chimezie Umezie
il 28 Ago 2012
Modificato: Chimezie Umezie
il 28 Ago 2012
Azzi Abdelmalek
il 28 Ago 2012
replace randi with round(nA1*rand(1,1))
Andrei Bobrov
il 28 Ago 2012
abc = [A,B,C]
[~,idx] = sort(rand(size(abc)))
out = abc(sub2ind(size(abc),idx,ones(size(abc,1),1)*(1:size(abc,2))));
Categorie
Scopri di più su Shifting and Sorting Matrices in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!