How to convert for loops to parfor loops?

1 view (last 30 days)
MFA
MFA on 6 Jan 2016
Answered: Walter Roberson on 6 Jan 2016
Hi guys, I'm new to Matlab. I have a question on converting for loops to parfor
I have a simple code just like below:
for i = 1:11
bucket(i) = bucket(i) + bucket(i-1)
Now, I know I cant convert directly because of the variable bucket(i), is there another way to convert this loop? I even tried using function for the body of the loop but the out come was different than expected.
Thank for your help

Answers (1)

Walter Roberson
Walter Roberson on 6 Jan 2016
No, that loop has an order dependence that cannot be removed. Any particular iteration cannot be computed until the iteration before is done to compute bucket(i-1) . parfor can only be used when the iterations can be calculated in any order.

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!