Cell array in parfor: variable cannot be classified

1 view (last 30 days)
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?

Answers (1)

José-Luis
José-Luis on 10 Oct 2014
Edited: José-Luis on 10 Oct 2014
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.

Community Treasure Hunt

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

Start Hunting!