我正在尝试将此循环作为 parfor 循环运行:
correlations = zeros(1,N);
parfor i = 1:(size(timestamps,1)-1)
j = i+1;
dts = timestamps(j) - timestamps(i);
while (dts < T) && (j <= size(timestamps,1))
if dts == 0 && detectors(i) ~= detectors(j)
correlations(1) = correlations(1) + 2;
elseif detectors(i) ~= detectors(j)
dts = floor(dts/binning)+1;
correlations(dts) = correlations(dts) + 1;
end
j = j + 1;
if j <= size(timestamps,1)
dts = timestamps(j) - timestamps(i);
end
end
end
Matlab给我以下错误:
Error: File: correlate_xcorr.m Line: 18 Column: 17
The variable correlations in a parfor cannot be classified.
See Parallel for Loops in MATLAB, "Overview".
第 18 行如下:
correlations(1) = correlations(1) + 2;
我不明白为什么这不应该是可能的。相关性的最终值不取决于循环执行的顺序,而仅取决于 dts 和检测器。我在文档中找到了类似的示例,它们可以正常工作。
为什么 Matlab 不能执行此代码,我该如何解决?