Effacer les filtres
Effacer les filtres

adding entities of 2 loops

1 vue (au cours des 30 derniers jours)
summyia qamar
summyia qamar le 4 Jan 2017
Commenté : summyia qamar le 4 Jan 2017
here is a code
[r1, c1]=size(Route)
for i=1:c1
E=0;
for j=1:Total_Operation
if Route{i}(j)~=0
E=E+Operations_Time{i}(j)*MakeToPart_Power(Route{i}(j));
end
end
Energy(i)=E
end
%setup_time
[r2,c2]=size(Route);
for k=1:c2
F=0;
for l=1:Total_Operation
if Route{k}(l)~=0
F=F+setup_Time{k}(l);
end
end
Setup(k)=F
end
after running, the results obtained are
Energy =
420 475 360 448 324 285 460 260 397 412 250 389
Setup =
7 9 12 10 7 7 8 7 7 9 6 8
I want to add each entity of both arrays for example
total=*420+7* *475+9* *360+12* etc..
and 2nd thing is there any better way to code them in one loop?

Réponse acceptée

Geoff Hayes
Geoff Hayes le 4 Jan 2017
summyia - just combine the code. Both loops iterate over the columns of Route and since the Setup does not depend upon the Energy, you should be able to do
[r1, c1]=size(Route)
for i=1:c1
E=0;
F=0;
for j=1:Total_Operation
if Route{i}(j)~=0
E=E+Operations_Time{i}(j)*MakeToPart_Power(Route{i}(j));
F=F+setup_Time{k}(l);
end
end
Energy(i)=E;
Setup(i)=F;
end
Then the total would be
total = Energy + Setup;
Try the above and see what happens!
  1 commentaire
summyia qamar
summyia qamar le 4 Jan 2017
thankyou so much..just before checking the answer, I did the same. :) your positive vibrations reached to me already

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by