How do I convert a for-Loop Into parfor-Loops?
显示 更早的评论
Im trying to use parfor-Loop to speed up the computation. Here is the code (a kind of customized pdist function):
for i = 1:size1-1
for j = i+1:size1
index = index + 1;
Y(index) = distance(dataSet(:,:,i),dataSet(:,:,j));
end
end
I'm using parfor for the outer loop, but I got an error message on parfor:
- "The PARFOR cannot run due the way variable index is used"
- "The PARFOR cannot run due the way variable Y is used"
and, in the inner loop:
- "Valid indices for Y are restricted in PARFOR loops"
Both the errors occurred because of the use of the indexes in the inner loop, I can't figure out how to change the code for avoiding this problem. I've read the documentation, but i can't figured out how to convert into a parfor loop. How should I use parfor in this context?
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!