Question: I am running a parfor loop in Matlab that takes a lot of time and I would like to know how many iterations are left. How can I get that info?

Answer: 
I don't believe you *can* get that information directly from MATLAB, short of printing something with each iteration and counting these lines by hand.

To see why, recall that each `parfor` iteration executes in its own workspace: while incrementing a counter within the loop is legal, accessing its "current" value is not (because this value does not really exist until completion of the loop). Furthermore, the `parfor` construct does not guarantee any particular execution order, so printing the iterator value isn't helpful.

```
cnt = 0;
parfor i=1:n
    cnt = cnt + 1; % legal
    disp(cnt); % illegal
    disp(i); % legal ofc. but out of order
end

```

Maybe someone does have a clever workaround, but I think that the independent nature of the `parfor` iterations belies taking a reliable count. The restrictions mentioned above, plus those on using `evalin`, etc. support this conclusion.

As @Jonas suggested, you could obtain the iteration count via side effects occurring outside of MATLAB, e.g. creating empty files in a certain directory and counting them. This you can do in MATLAB of course:

```
fid = fopen(['countingDir/f' num2str(i)],'w');
fclose(fid);
length(dir('countingDir'));

```
Try this FEX file: <http://www.mathworks.com/matlabcentral/fileexchange/32101-progress-monitor--progress-bar--that-works-with-parfor>

You can easily modify it to return the iteration number instead of displaying a progress bar.