function parfor_waitbar(f, totalJobs, detail, reset) persistent done if reset done = 0; if ishandle(f) if isempty(detail) waitbar(0, f, "Starting"); else waitbar(0, f, detail); end end return end if isempty(done) done = 0; end done = done + 1; if ishandle(f) progressText = sprintf("Done %d/%d", done, totalJobs); if ~isempty(detail) progressText = sprintf("%s | %s", progressText, char(detail)); end waitbar(min(done / totalJobs, 1), f, progressText); end end