FOR loop on rows of a matrix

조회 수: 8 (최근 30일)
summyia qamar
summyia qamar 2017년 1월 4일
댓글: 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에서 Mathematics and Optimization에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by