How can I vectorize this code?
조회 수: 1 (최근 30일)
이전 댓글 표시
Hello everyone, I am trying to vectorize the following loop but I don´t quite get how to do it:
c=5;
for i=1:Machines;
for j=1:degradationbyM(i);
distLoadDec(i,j)=initialDataV(c,1);
paramDistLoadDec(i,j,1)=initialDataV(c,2);
paramDistLoadDec(i,j,2)=initialDataV(c,3);
paramDistLoadDec(i,j,3)=initialDataV(c,4);
c=c+1;
end
end
Thank you.
댓글 수: 2
John Petersen
2012년 12월 18일
Do these loops do exactly what you want? I see that the matrices in your for loop will not completely be filled. Is this your intention to have a variable index degredationbyM? You haven't shown any initialization for these matrices, or defined contador.
채택된 답변
Walter Roberson
2012년 12월 18일
c=5;
for i=1:Machines;
j = 1:degradationbyM(i); %not a "for" loop!
distLoadDec(i, j) = initialDataV(c+j-1, 1);
paramDistLoadDec(i, j, 1:3) = initialDataV(c+j-1, 2:4);
c = c + degradationbyM(i);
end
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!