Cell array in parfor: variable cannot be classified

1 回表示 (過去 30 日間)
Florian
Florian 2014 年 10 月 10 日
コメント済み: Florian 2014 年 10 月 10 日
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.
  1 件のコメント
Florian
Florian 2014 年 10 月 10 日
I see. I will index the cell using just cpu_id then. Thanks!

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeCall Python from MATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by