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
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.
Daniel Shub
Daniel Shub 2012-12-19
Why do you want to vectorize the code?

请先登录,再进行评论。

采纳的回答

Walter Roberson
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 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by