How can I vectorize this code?
1 view (last 30 days)
Show older comments
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 Comments
John Petersen
on 18 Dec 2012
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.
Accepted Answer
Walter Roberson
on 18 Dec 2012
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 Comments
More Answers (0)
See Also
Categories
Find more on Loops and Conditional Statements 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!