Pergunta

While using parfor in MATLAB using cell arrays I stepped into a problem where I can't see any difference from working example code and my buggy line!

The modification of data can be done indipendently for each worker and I wanted to use the slicing of variables, like shown in MathWorks Blog

A3 = cell(10,1);
parfor ix = 1:10
    for jx = 1:10
        A3{ix}(jx) = ix + jx;
    end
end
A3 = cell2mat(A3);

Im doing the exactly same first level indexing like in the example, but MATLAB can't classify it.

I want certain lines to be deleted: There are file Files with each lines Lines that are compared against some values in (for simplicity not shown) other loops. For each file a worker will be assigned.

parfor file=1:length(data(:,1))
    line= 1;
    length_line = length(data{file,1}(:,1));

    while line <= length_line && ... && ...
       % some more loops
           if (...)
              data{file,1}(line,:) = [];
              length_line= length_line - 1;
           end
       % end of some more loops
       line= line + 1;
    end
end
% data will be returned

I don't see why it should not work! What i took into account:

  • data will be modified so that each workers modification has no cross influence to others ( deleted lines are only a subset part of actual worker data)
  • for slicing indexing must be done in first level ( data{file,1} )
  • other first level indexing variables will be treated as constant / are constants, I use "1" so everything is good.
  • No in-parloop assignment of variables that later will be used outside (not even constants)
  • Testing without the line data{file,1}(line,:)= [] runs without Matlab warnings.
  • Tried MATLAB static code analyser output = mlint('myFile.m') but it doesn't show me any useful hints.

Just this single line is breaking up everything. But I really need this command to work. Any hints / workarounds?

Foi útil?

Solução

Your code is incomplete, I did not try it out, but this should fix it:

parfor file=1:length(data(:,1))
    line= 1;
    length_line = length(data{file,1}(:,1));
    dataslice=data{file,1}
    while line <= length_line && ... && ...
       % some more loops
           if (...)
              dataslice(line,:) = [];
              length_line= length_line - 1;
           end
       % end of some more loops
       line= line + 1;
    end
    data{file,1}=dataslice
end
% data will be returned

If this does not help, please update your question and provide a reproducable example (initialisation of all variables, complete code)

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top