change value in cells based on conditions
조회 수: 1 (최근 30일)
이전 댓글 표시
how can i get the expected output like this?
[11 11 22 22 33 33 44;
11 11 33 33 44 22 22;
22 22 11 11 33 33 44;
22 22 33 33 44 11 11;
33 33 44 11 11 22 22;
33 33 44 22 22 11 11;
44 11 11 22 22 33 33;
44 22 22 11 11 33 33]
the conditions are:
1. each value ( 11,22,33) must be appeared 2 times continously.
11 22 = 11 11
11 33 = 11 11
22 11 = 22 22
22 33 = 22 22
33 11 = 33 33
33 22 = 33 33
2.after value 33 33 must 44
33 33 11 = 33 33 44
33 33 22 = 33 33 44
33 33 33 = 33 33 44
3. after value 44 cannot be value 33 and 44
44 33 = 44 11
44 44 = 44 22
the inputs are undergoing selection,crossover and mutation process.
input :
a=[11 22 33 44]
I need help to code this problem.
Thank you for your help.
댓글 수: 0
답변 (1개)
Andrei Bobrov
2012년 6월 17일
A = {[11 11] [22 22] [33 33 44]}
idx = sortrows(perms(1:3));
A2 = A(idx);
out = cell2mat(arrayfun(@(i1)[A2{i1,:}],(1:size(idx,1))','un',0));
out = [out;out(idx(:,end) == 3,circshift(1:size(out,2),[0 1]))];
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Genetic Algorithm에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!