How to generate a no. of permutations(lets say 100) of a particular row of a matrix(consisting of 30 coloumns) and store the generated permutation into another array row wise??
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
UTKARSH SINGH
am 4 Apr. 2015
Kommentiert: Image Analyst
am 3 Mär. 2016
Basically I am trying to generate population for my chromosome in genetic algorithm. I have made an array of 30 elements and now to generate the population, I have to permutate the elements of the array and store these permutations in form of a matrix row wise.Now can I do this using permute and other permutation functions in matlab or will I have to make a different method to generate this.Any reference codes shall be very helpful.
0 Kommentare
Akzeptierte Antwort
Roger Stafford
am 4 Apr. 2015
If r is the 30-element row vector being used, do this:
m = 100;
n = 30;
[~,p] = sort(rand(m,n),2);
s = reshape(r(p),m,n);
The rows of matrix s will each be a random permutation of r.
2 Kommentare
Triveni
am 3 Mär. 2016
Is it possible to generate 500 random permutations of
[90 90 -45 0 0 45 45 0 -45 15 30 -30 75 -45 75 -75 45 45 0 -45 15 30 ]
Image Analyst
am 3 Mär. 2016
Yes
m = [90 90 -45 0 0 45 45 0 -45 15 30 -30 75 -45 75 -75 45 45 0 -45 15 30 ];
newSortingOrder = randperm(length(m));
mScrambled = m(newSortingOrder);
Just call that code 500 times to get 500 different permutations.
Weitere Antworten (1)
Image Analyst
am 4 Apr. 2015
Bearbeitet: Image Analyst
am 4 Apr. 2015
Try randperm() or randi().
newSortingOrder = randperm(30);
0 Kommentare
Siehe auch
Kategorien
Mehr zu Genetic Algorithm finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!