# parfor unable to classify, why?

5 views (last 30 days)

Show older comments

Can someone explain why the ind2sub first statement triggers the error, but the second works fine?

m = 2;

n = 3;

mycell = cell(m,n);

parfor k = 1:numel(mycell)

[i,j] = ind2sub(size(mycell), k); % MATLAB complains cannot classify mycell because of this

%[i,j] = ind2sub([m n], k); % this iis however accepted

mycell{k} = 1;

end

##### 0 Comments

### Accepted Answer

Matt J
on 4 Jan 2023

Edited: Matt J
on 4 Jan 2023

I suspect it is because mycell is intended to be a sliced variable, but the code violates the fixed indexing rule,

Fixed Index Listing. Within the first-level indexing of a sliced variable, the list of indices is the same for all occurrences of a given variable.

since in one place you index mycell with {k} and elsewhere you do not index it at all. Notice that this also doesn't work:

m = 2;

n = 3;

mycell = cell(m,n);

parfor k = 1:numel(mycell)

mycell;

mycell{k} = 1;

end

I also vaguely wonder if it makes sense for a parpool worker to try to determine the size() of a sliced variable when it only receives a piece of it.

##### 5 Comments

Matt J
on 5 Jan 2023

Edited: Matt J
on 5 Jan 2023

Edric Ellis
on 5 Jan 2023

### More Answers (0)

### See Also

### Categories

### Community Treasure Hunt

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

Start Hunting!