MATLAB: Hello, I want to use temporary variable value after parfor loop!, how can this achieved?

Parallel Computing Toolboxparforparfor temporary variables

counter =0;
parfor i = 1:1000
max=999;
if max < i
max = i;
disp(max);
assignin('base','counter',max);
end
end
disp(counter);
For example, I want to keep max value but I got zero

Best Answer

Create cmsc as a struct array of full size. Assign to cmsc(i) as appropriate. Also keep a logical vector used(i) =true where the condition is met. After the parfor cmsc = cmsc(used)
That graph might be more of a problem. Your code structure tends to hint that you are using information from previous iterations in updating the graph.