nested loop in eval command and generalized the programme
Afficher commentaires plus anciens
hi all
i want to generalized the following program. the theme is...actually i want to pair in the following manner, gudx1-gudx2, 1-3, 1-4, 1-5, 2-3, 2-4, 2-5, 3-4, 3-5, 4-5, 5-1, 5-2, 5-3, 5-4
pair with itself and decreasing one is not allowed except the final variable, who can pair with all variable below him except himself.
and 2nd main point is changing of any variable chx1,chx2,chx3,chx4,chx5 is allowed only one time, means we cannot change a value of above variable twice or thrice.
chx1=genx1
chx2=genx2
chx3=genx3
chx4=genx4
chx5=genx5
if ((gudx1>0) & (gudx2>0))
if (chx1==genx1)
chx1= gudx2;
end
end
if ((gudx1>0) & (gudx3>0))
if (chx1==genx1)
chx1= gudx3;
end
end
if ((gudx1>0) & (gudx4>0))
if (chx1==genx1)
chx1= gudx4;
end
end
if ((gudx1>0) & (gudx5>0))
if (chx1==genx1)
chx1= gudx5;
end
end
if ((gudx2>0) & (gudx3>0))
if (chx2==genx2)
chx2= gudx3;
end
end
if ((gudx2>0) & (gudx4>0))
if (chx2==genx2)
chx2= gudx4;
end
end
if ((gudx2>0) & (gudx5>0))
if (chx2==genx2)
chx2= gudx5;
end
end
if ((gudx3>0) & (gudx4>0))
if (chx3==genx3)
chx3=gudx4;
end
end
if ((gudx3>0) & (gudx5>0))
if (chx3==genx3)
chx3=gudx5;
end
end
if ((gudx4>0) & (gudx5>0))
if (chx4==genx4)
chx4= gudx5;
end
end
if ((gudx5>0) & (gudx1>0))
if (chx5==genx5)
chx5= gudx1;
end
end
if ((gudx5>0) & (gudx2>0))
if (chx5==genx5)
chx5= gudx2;
end
end
if ((gudx5>0) & (gudx3>0))
if (chx5==genx5)
chx5= gudx3;
end
end
if ((gudx5>0) & (gudx4>0))
if (chx5==genx5)
chx5= gudx4;
end
end
i have tried but i know this one is logically and syntax wise is wrong.
for i:1:numChromosomes
for j=i+1:numChromosomes
eval(sprintf('if ((gudx%d>0) & (gudx%d>0))',[i j],'if(chx%d==gen%d)',[i i],'chx%d==gud%d',[i j],end,end))
end
end
kindly help me too generalize it i will be highly thankful to you
regards
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Solver Outputs and Iterative Display dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!