How to shuffle a matrix

4 vues (au cours des 30 derniers jours)
Aryama Mandal
Aryama Mandal le 4 Juin 2015
Commenté : Aryama Mandal le 4 Juin 2015
I have a matrix v=[0 1;1 0;0 1;1 0] I want to shuffle this matrix, which will give
x=[1 0;1 0;0 1;0 1] x=[1 0;0 1;1 0;0 1]
I mean all the possibilities of this type of arrangement. As I want to generate the chromosome for genetic algorithm

Réponse acceptée

Guillaume
Guillaume le 4 Juin 2015
Assuming you just want to shuffle the rows, I would do it like this:
v = [0 1;1 0;0 1;1 0];
[~, ~, rowidx] = unique(v, 'rows'); %identical rows have the same index in rowidx
rowperms = unique(perms(rowidx), 'rows'); %generate all permutations of the indices, and remove duplicate
allv = cellfun(@(rowperm) v(rowperm, :), num2cell(rowperms, 2), 'UniformOutput', false)
  3 commentaires
Guillaume
Guillaume le 4 Juin 2015
Then don't bother with the first two lines and generate rowperms simply with:
rowperms = perms(1:size(v, 1));
Aryama Mandal
Aryama Mandal le 4 Juin 2015
Thank you.

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by