The variable in a parfor cannot be classified, parfor

6 views (last 30 days)
Hi, I have tried to convert my problem in a simple form. I know that I have to take care of the indexing in parfor loops, but I don't know how can avoid the problem that one line depends on the previous one. Please check the code and you will understand. Hope you can help me Marc
num_col = 1000;
days_simulation = 400;
SimulationPQ = nan(days_simulation,num_col);
Ergebnis = nan(days_simulation,num_col);
Ergebnis (1,:) = ones(1,num_col);
parfor kk=1:100
for simday = 1:400
SimulationPQ(simday,kk) = rand();
Ergebnis(simday+1,kk) = Ergebnis(simday,kk) * SimulationPQ(simday,kk) ;
end
end

Accepted Answer

Adam
Adam on 18 Jan 2018
Edited: Adam on 18 Jan 2018
Something similar to this should work (it gives no M-Lint warnings at least)
num_col = 1000;
days_simulation = 400;
SimulationPQ = nan(days_simulation,num_col);
Ergebnis = nan(days_simulation,num_col);
Ergebnis (1,:) = ones(1,num_col);
parfor kk=1:100
localErgebnis = Ergebnis(:,kk)
for simday = 1:399
SimulationPQ(simday,kk) = rand();
localErgebnis(simday+1) = localErgebnis(simday) * SimulationPQ(simday,kk) ;
end
Ergebnis(:,kk) = localErgebnis;
end
except that simday+1 will go out of range, but that is just a general problem with your example, nothing to do with the parallel processing aspect.
  3 Comments
Jan
Jan on 19 Jan 2018
Marc: if this answer solves your problem, please accept it. Then the readers in the forum can see, that you do not need help anymore. Thanks.
Marc Paul
Marc Paul on 19 Jan 2018
You're right. I clicked only the link in my mail to accept the answer and thought thtat's it. Sorry. Already corrected :)

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!