FOR loop on rows of a matrix
7 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Operations_Time{1}=[10 0 0 10 0 20 15;2 0 0 2 0 2 1];
Operations_Time{2}=[10 13 0 0 12 0 15;2 2.5 0 0 3 0 1];
Route{1}=[1 0 0 4 0 6 7];
Route{2}=[1 2 0 0 5 0 7];
total_operations=5
MakeToPart_Power=[12 7 4 6 12 6 8];
setupcost_ofParts=[2 4 3 2.5 3.5 2];
[r1, c1]=size(Route)
for i=1:c1
E=0;
for j=1:6
if Route{i}(j)~=0
E=E+Operations_Time{i}(j)*MakeToPart_Power(Route{i}(j))
end
end
Energy(i)=E
end
the desired objective is the * application of E on 1st row of Operation_time{i}* and another function value iterate on 2nd row of Operation_time{i}.for example 'F' runs for 2nd row of operation time with same valu of (i) F=Operation_time{i}*setupcost_ofparts
0 Commenti
Risposte (1)
Walter Roberson
il 4 Gen 2017
To loop over the rows of the matrix A you can use
for this_row = A.'
This will make this_row a column vector that contains one row at a time of A. You will only get the contents of the row, not any information about which row it is.
If you need information about which row you are processing then you should loop over row numbers and extract the content of the row using matrix indexing.
Vedere anche
Categorie
Scopri di più su Mathematics and Optimization in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!