naming columns and better coding

PP1=[1 1;0 1.3;0 0;1 0;0 1.2;2 0;1.5 1.5];
PP2=[0 1.1;1 0;1 1.3;1.5 0;0 1.7;0 10;2 0];
PP3=[1 0;0 1.1;0 1.8;1.2 0;1.1 0;0 0;0 1.7];
PP4=[1 0;0 1.4;0 0;0 1.7;1.9 0;0 1;1.4 0];
PP5=[1.8 1;1.3 1.2;0 0;0 0;0 10;1.5 0;0 1.1];
PP6=[0 1.2;1 1.1;0 0;0 1.3;0 0;1 1.5;1.5 0];
machine_power=[12;7;4;6;12;6;8];
cost=0.5;
E1=sum(bsxfun(@times,PP1,machine_power));
E2=sum(bsxfun(@times,PP2,machine_power));
E3=sum(bsxfun(@times,PP3,machine_power));
E4=sum(bsxfun(@times,PP4,machine_power));
E5=sum(bsxfun(@times,PP5,machine_power));
E6=sum(bsxfun(@times,PP6,machine_power));
z = [];
for a = E1
for b = E2
for c = E3
for d=E4
for f=E5
for g=E6
total_cost= C*(600*a+550*b+620*c+500*d+590*f+600*g);
z = [z; a b c d f g total_cost];
end
end
end
end
end
end
minVal=min(z)
the variables a,b,c,d...consist of 2 values/columns. How can I name them so that when I get the result I can identify that which column is selected for a,b, c, d, etc. e.g the value of 1st column of a=47 and 2nd is 54 so in the result matrix if 47 is selected it get the name 'route 1'and if 54 is selected it get the name 'route 2' likewise all the other variables(b,c,d,f,g) get 1st value as 'route 1' and 2nd value as 'route 2'

3 个评论

I would start by not using 6 nested loops, as has been suggested in questions you have asked previously.
i tried that buts for this case its giving error
Time to graduate! Learn to use MATLAB. Numbered variables and named columns suggests you are trying to use MATLAB as if you are still using a spreadsheet.

请先登录,再进行评论。

回答(0 个)

类别

帮助中心File Exchange 中查找有关 Programming 的更多信息

产品

编辑:

dpb
2016-12-16

Community Treasure Hunt

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

Start Hunting!

Translated by