The variable in a parfor cannot be classified, parfor
6 views (last 30 days)
Show older comments
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
0 Comments
Accepted Answer
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
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.
More Answers (0)
See Also
Categories
Find more on Matrix Indexing 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!