You probably intended to do
b = a.^2;
instead of
b = a^2;
Without the .
, the multiplication is a "matrix multiplication" (in fact, the name mpower
suggests that it is literally exponentiation of a matrix); with the .
, it is an "element by element multiplication". I am guessing that matrix multiplication doesn't work well (at all?) for distributed matrices - on the other hand, according to this link it actually happens implicitly without the need for distribution.
It leaves the question: did you intend for matrix multiplication, or element-by-element multiplication?
EDIT
You indicated in the comment that the reason for your question was that you were evaluating a function:
function g = sigmoid2(z)
g = distributed.zeros(size(z));
%g = arrayfun(@(x) (1 / (1+(exp^-(x)))),z);
for idx = 1: numel(z)
g(idx) = 1 / (1+ (exp(1).^-z(idx)));
end
end
and were wondering if there is a quicker way to do this. Indeed there is. Instead of looping over idx, use the single matrix operation
g = 1./(1+exp(-z));
as your function definition - it will be many times faster. Matlab is powerful but there is a lot of overhead executing each line - so avoid loops if you can. Learn about vectorization in Matlab (look it up). Distributing doesn't always speed things up - it depends on the operation and the size of the matrices. Use the profiling tool to find out what line takes the most time - then use that knowledge to focus your speed up efforts. Good luck!