MATLAB: Undefined operator ‘:’ for input arguments of type ‘parallel.Pool’

parallel computingParallel Computing Toolboxparpool

These are the code:
% chunk the data up
numData = size(X,2) ;
numChunks = parpool('local', 2);
data = Composite() ;
dist = Composite() ;
assign = Composite() ;
for i = 1:numChunks;
chunk = i:numChunks:numData ;
data{i} = X(:, chunk) ;
dist{i} = inf(1, numel(chunk), class(X)) ;
assign{i} = zeros(1, numel(chunk)) ;
end
When I run the code, it shows error Undefined operator ':' for input arguments of type 'parallel.Pool'.
First, what mean by that error ? And what should I do to solve this error?
Thank you.

Best Answer

I suspect you expected parpool to return the number of workers in the pool or something similar. It doesn't. It returns an object representing the pool. That object doesn't know how to behave when used as one of the values in a call to the colon operator (:) -- colon just isn't defined for that object. However it does has a property NumWorkers that contains the number of workers in the pool. So if you want your loop to iterate over the workers:
for i = 1:numChunks.NumWorkers
If that's not what you're trying to do, please explain in more detail what you expect / want numChunks to represent and we may be able to offer some guidance for how to achieve your goal.