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!