MATLAB: How to use the MATLAB SAVE function inside a PARFOR loop in Parallel Computing Toolbox 5.1 (R2011a)

Parallel Computing Toolbox

I want to use the SAVE function inside PARFOR loop

Best Answer

It is possible to use the exact SAVE function inside a PARFOR loop. All you need to do is to create a wrapper function on top of SAVE and call it inside PARFOR. An example code snippet is shown below:
parfor ii=1:10
x = magic(ii);
fname = sprintf( 'file_%d', ii );
iSaveX( fname, x );
end
% wrapper around SAVE function
function iSaveX( fname, x )
save( fname, 'x' );
end