Cell array in parfor: variable cannot be classified

1 次查看(过去 30 天)
Hi,
My code looks like this:
allFileFeatures = cell(1,numel(data));
sliced_data_size = round(numel(data)/10);
parfor cpu_id = 1:10
last_ind = min(cpu_id*sliced_data_size,numel(data));
first_ind = (cpu_id-1)*sliced_data_size+1;
sliced_data = data(first_ind:last_ind);
for i = 1:numel(sliced_data)
%stuff = ...
global_i = cpu_id*sliced_data_size+i;
allFileFeatures{global_i} = stuff;
I get: "The variable allFileFeatures in a parfor cannot be classified." Google lists a lot of results on this error but I still cannot find the problem in this particular snippet. How can I correct it?

回答(1 个)

José-Luis
José-Luis 2014-10-10
编辑:José-Luis 2014-10-10
Your cannot index like that. From the documentation on sliced variables:
Form of Indexing. Within the list of indices for a sliced variable, one of these indices is of the form i, i+k, i-k, k+i, or k-i, where i is the loop variable and k is a constant or a simple (nonindexed) broadcast variable; and every other index is a scalar constant, a simple broadcast variable, colon, or end
Point in case, you cannot define global_i like that. I guess it boils down to the interpreter not being smart enough to see there is no race condition.

类别

Help CenterFile Exchange 中查找有关 Call Python from MATLAB 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by