|It looks like there exists a simple solution which involves creating a COM object inside the spmd body, but avoids creating an anonymous function there. One has to create the anonymous function outside the spmd body, and indicate COM object as one of _variables_ (not parameters) like in the example code below. First you define an external function somewhere:|
function y = exFunction(x,oApp,c)
% Find the square of x and does nothing to oApp
y = c * x.^2;
% Display argument oApp to check if it is of type
% COM.Excel_Application
oApp
end
Then the script with spmd body will look like:
matlabpool open 2
% specify the additional parameter:
c = 3; % whatever values you need
%Create a Function handle of function exFunction
fhun = @(x,oApp) exFunction(x,oApp,c);
spmd
if labindex==1
R = rand(2,2)
else
%Create a COM server running Microsoft Excel
oApp = actxserver ('Excel.Application')
% Pass 'oApp' to exFunction
R = fhun(5,oApp)
end
end
matlabpool close