FOR loop on rows of a matrix

14 views (last 30 days)
summyia qamar
summyia qamar on 4 Jan 2017
Commented: summyia qamar on 4 Jan 2017
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

Answers (1)

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

Sign in to comment.

Categories

Find more on Multidimensional Arrays in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!