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 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