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

 채택된 답변

Guillaume
Guillaume 2015년 6월 4일

1 개 추천

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

Aryama Mandal
Aryama Mandal 2015년 6월 4일
If I don't want to remove he duplicate than.
Then don't bother with the first two lines and generate rowperms simply with:
rowperms = perms(1:size(v, 1));
Aryama Mandal
Aryama Mandal 2015년 6월 4일
Thank you.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

질문:

2015년 6월 4일

댓글:

2015년 6월 4일

Community Treasure Hunt

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

Start Hunting!

Translated by