Justin - I think what you can do is create another timer to periodically update the status bar, rather than relying a while loop that is called from within a hidden button (your pushbutton8).
For example, in the GuiTImerUpdateTextExample_OpeningFcn, you can instantiate your two timers, the original one and one for your progress bar as
handles.timerQuery = timer('Name','MyQueryTimer', ...
'Period',3, ...
'StartDelay',1, ...
'TasksToExecute',inf, ...
'ExecutionMode','fixedSpacing', ...
'TimerFcn',{@timerQueryCallback,hObject});
handles.timerProgress = timer('Name','MyProgressTimer', ...
'Period', 0.01, ...
'TasksToExecute',inf, ...
'ExecutionMode', 'fixedSpacing', ...
'TimerFcn', {@timerProgressCallback, hObject});
The "query timer" will expire after three seconds, corresponding to the query that is asked of the user. The "progress timer* will expire every 10 milliseconds and will call the timerProgressCallback. Once we have created the timers, we can initialize your progress axes as
cla(handles.axes1);
set(handles.axes1,'Visible','on','color',[.9 .85 .3]);
axis(handles.axes1,[0,1,0,1]);
handles.hPatch = patch([0,0,0,0],[0,0,1,1],'g');
axis(handles.axes1, 'off');
Note how we create the patch and save its handle to the handles structure. We do this so that we can update this patch object rather than creating a new one every time we want to update the progress "bar".
We then save the updated handles structure and start the the query timer as
guidata(hObject, handles);
start(handles.timerQuery);
We don't start the other timer as we rely on the timerQueryCallback to do this for us as
function timerQueryCallback(hTimer, eventdata, hFigure)
handles = guidata(hFigure);
stop(handles.timerProgress);
if ~isempty(get(handles.pushbutton1,'String'))
set(handles.hPatch,'XData',[0 1 1 0]);
pause(0.5);
end
set(handles.hPatch,'XData',[0 0 0 0]);
tic;
start(handles.timerProgress);
That just leaves the timerProgressCallback which can be defined as
function timerProgressCallback(hObject, eventdata, hFigure)
handles = guidata(hFigure);
if ~isempty(handles)
periodQuery = get(handles.timerQuery,'Period');
percentComplete = double(toc)/periodQuery;
set(handles.hPatch,'XData',[0 percentComplete percentComplete 0]);
end
We use toc and the period of the query timer to determine the progress and so how much of the patch to draw.
Try the above and see what happens! (See the attached for a working example.)
Best Answer