Parfor and cell array

2 views (last 30 days)
Michael
Michael on 21 Oct 2014
Answered: Michael on 21 Oct 2014
Suppose I have the following code
p = cell(1,3);
w = zeros(5,3);
p{1} = X; 2 by 2 matrix
p{2} = Y; 2 by 2 matrix
p{3} = Z; 2 by 2 matrix
parfor k=1:3
for i=1:5
w(i,k) = somefunction(variable1, variable2,p{k})
end
end
If I remove the parfor, the code runs fine, but if I use the parfor I get the error: Output argument "XXXX" from some other function that is used in "somefunction" was not assigned during call.
Sorry for being very schematic but the actual code is very long has and uses numerous functions.

Accepted Answer

José-Luis
José-Luis on 21 Oct 2014
It works for me:
p = cell(1,3);
w = zeros(5,3);
p{1} = rand(2);
p{2} = rand(2);
p{3} = rand(2);
myFun = @(x,y,z) x + y + sum(z(:));
variable1 = 1;
variable2 = 2;
parfor k=1:3
for i=1:5
w(i,k) = myFun(variable1, variable2,p{k})
end
end
I'm afraid you'll have to provide more details about variable1, variable2 and somefunction()

More Answers (1)

Michael
Michael on 21 Oct 2014
Figured it out, a portion of the workers were working with variables p{k} that had a defective input. The matrices were not Hermitian and the code only works if they are. Running each iteration separately helped.

Categories

Find more on Parallel for-Loops (parfor) in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!