Cell array in parfor: variable cannot be classified

1 Ansicht (letzte 30 Tage)
Florian
Florian am 10 Okt. 2014
Kommentiert: Florian am 10 Okt. 2014
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?

Antworten (1)

José-Luis
José-Luis am 10 Okt. 2014
Bearbeitet: José-Luis am 10 Okt. 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.
  1 Kommentar
Florian
Florian am 10 Okt. 2014
I see. I will index the cell using just cpu_id then. Thanks!

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Call Python from MATLAB finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by