Files
imdd_silas/Functions/updateWaitbar.m
Silas Labor Zizou bf94e3dc2f Work on lab PC
- many new automations
- scripts to record and save MPI and bias optimizations...
2024-10-15 08:43:34 +02:00

46 lines
1.4 KiB
Matlab

function updateWaitbar(currentIteration, totalIterations)
if currentIteration == 1
% Check if the waitbar already exists using its unique Tag
hWaitbar = findobj('Tag', 'MyUniqueWaitbar');
if isempty(hWaitbar) || ~ishandle(hWaitbar)
% Create a waitbar with a unique Tag if it doesn't exist
hWaitbar = waitbar(0, 'Starting process...', 'Name', 'Processing Progress', 'Tag', 'MyUniqueWaitbar');
else
% Waitbar exists, reset the progress bar
waitbar(0, hWaitbar, 'Resuming process...');
end
elseif currentIteration == totalIterations+1
% Check if the waitbar already exists using its unique Tag
hWaitbar = findobj('Tag', 'MyUniqueWaitbar');
% Close the waitbar after the loop is completed
if ishandle(hWaitbar)
close(hWaitbar);
end
else
% Check if the waitbar already exists using its unique Tag
hWaitbar = findobj('Tag', 'MyUniqueWaitbar');
% Calculate the progress fraction
progressFraction = currentIteration / totalIterations;
% Update the waitbar's progress and message
if ishandle(hWaitbar)
waitbar(progressFraction, hWaitbar, ...
sprintf('Progress: %d/%d', currentIteration, totalIterations));
else
% % If the waitbar was closed, recreate it
% hWaitbar = waitbar(progressFraction, 'Resuming process...', 'Name', 'Processing Progress', 'Tag', 'MyUniqueWaitbar');
end
end