I have a piece of code that divides a image matrix img into small piece and work on them parallel. But Matlab says parfor loop cannot be used, because the way outC{i,j} is indexed. How do I fix this?
The sub matrices are of different size. If img=[4x7], then
C=[3x3 3x3 3x1;
1x3 1x3 1x1]
On a side note, I’m not sure if using cell array is a good idea here. If not, feel free to give suggestion on how to divide up the img as well.
C=mat2cell(img, rowSplit, colSplit);
[rowc,colc]=size(C);
outC=cell(rowc,colc);
parfor i=1:rowc
for j=1:colc
outC{i,j}=doWork(C{i,j});
end
end
You can use linear indexing for both the input and output.
First I make a pretend input of your shape, and a simple
doWorkfunction:Then use linear indexing:
A quick check that it’s worked: