I do not believe that you can get this information directly from MATLAB without printing something with each iteration and reading these lines manually.
To find out why, remind you that each parfor iteration parfor performed in its own workspace: while incrementing a counter in a loop is legal, accessing its βcurrentβ value is not (since this value does not really exist until the loop completes). In addition, the parfor construct parfor not guarantee any particular execution order, so printing the value of an iterator is not useful.
cnt = 0; parfor i=1:n cnt = cnt + 1; % legal disp(cnt); % illegal disp(i); % legal ofc. but out of order end
Someone might have a smart workaround, but I think the independent nature of the parfor iterations contradicts the correct count. The limitations mentioned above, plus those that use evalin , etc., support this conclusion.
As suggested by @Jonas, you can get an iteration counter using side effects that happen outside of MATLAB, for example. creating empty files in a specific directory and counting them. This can be done in MATLAB, of course:
fid = fopen(['countingDir/f' num2str(i)],'w'); fclose(fid); length(dir('countingDir'));
source share