I am having a problem updating a waitbar in a MATLAB GUI.
I created a simple example that works as expected.
steps = 5;
hWaitBar = waitbar(0, 'Testing...');
for i = 1:steps
waitbar(i/steps, hWaitBar);
pause(1);
end
close(hWaitBar);
However when I use this construction in the GUI...
numSteps = %calculated
hWaitBar = waitbar(0, 'Processing...');
if %conditional
for i = 1:numSteps
waitbar(i/numSteps, hWaitBar)
% additional processing
end
else %conditional
% additional processing
end
close(hWaitBar);
...the waitbar only displays correctly for the first for loop iteration.
The second interation fails with the execption:
Error using waitbar(109)
Improper arguments for waitbar.
- I have verified that the waitbar progress value does not exceed 1.
- I have verified that the waitbar is not being closed until outside the if/else loop.