MATLAB: How to shuffle a matrix

genetic algorithmmatrix manipulation

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

Best Answer

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)