FOR loop on rows of a matrix

5 次查看(过去 30 天)
summyia qamar
summyia qamar 2017-1-4
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

回答(1 个)

Walter Roberson
Walter Roberson 2017-1-4
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.
  1 个评论
summyia qamar
summyia qamar 2017-1-4
couldn't understand this for my particular question..however solved by separately defining the 2 rows

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Multidimensional Arrays 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by