Hi Hussein,
All MATLAB tokens must either be functions or variables. Keep in mind, regardless of whether or not code will be executed, MATLAB needs to serialize the entire parfor block to each of the workers. When it sees allocatedVars, it needs to inform the workers if it's a function or variable. If a function, it might also be serialized and passed down (or it could be on the worker's path already).
Because MATLAB doesn't see allocatedVar as a variable, it assumes it's a function. But calling a function with {} is invalid (hence the first part of the error string). MATLAB then suggests initialize it to be a variable if that's what you meant (which it is), overriding the default assumption of a function (though the suggestion won't work here).
I wonder if using parallel.pool.Constant could help to avoid generating the data on the client to begin with. From the doc
Make parallel.pool.Constant from Composite
This example shows how to build large data sets as a Composite on pool workers inside an spmd block, and then use that data as a parallel.pool.Constant inside a parfor-loop.
spmd
if labindex == 1
x = labBroadcast(1,rand(5000));
else
x = labBroadcast(1);
end
end
xc = parallel.pool.Constant(x);
parfor idx = 1:10
s(idx) = sum(xc.Value(:,idx));
end
Thanks,
Raymond