change value in cells based on conditions
1 view (last 30 days)
Show older comments
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 Comments
Answers (1)
Andrei Bobrov
on 17 Jun 2012
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 Comments
See Also
Categories
Find more on Genetic Algorithm in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!