[flag, h, callbackFcn] = progressbar(v, h, title);

Create and update a progress bar using Matlab's waitbar function. Includes a cancel button. Outputs a function handle that can be used as a callback function.

v [vector] 
Vector containing the index of the current iteration and the total number of iterations. May contain multiple index/total pairs. Pass as [] to initialize a new progress bar. 
h [handle] 
Wait bar handle to update. Only required if v is not empty. Must be created using Matlab function waitbar. Pass as empty ([]) to specify window title. 
title [string] 
(Optional) Title for progress bar window. Can include '%' to be replaced with the percentage complete based on the input vector. 
Return Values
Return Values 
flag [logical] 
Flag indicating whether update of the waitbar was successful 
h [handle] 
Object handle for the waitbar 
callbackFcn [function_handle] 
Function handle for updating the waitbar that can be passed to other functions that allow a callback function input. 

>> [flag, h, callbackFcn] = progressbar([], [], 'Running (%)'); 

  • Initialize a progress bar. The output handle h can be used to modify the progress bar in any way.
>> flag = progressbar([2,10],h,'Running (%)'); 

  • Pass loop indices to update the progress bar. Output flag will be false if the user pushed the cancel button.
>> flag = callbackFcn([2 10 2 3]) 

  • Same as above, except that it uses the function handle to access the progress bar. Also includes indices for multiple/nested loops.
>> RunMySimulation(parameters, callbackFcn) 

  • Pass the function handle for updating the progress bar to a separate Matlab function that checks and updates the progress bar.

Made with Doc-O-Matic.
Copyright (c) 2009. All rights reserved.
What do you think about this topic? Send feedback!