Hello,
My problem is that in my GUI, I have six pushbuttons with alternating text. I also have a status bar to indicate how much time the user has to select a button. My problem is that the change in text and the status bar is not synced. When I do get it to sync, the status bar is opened in another window, instead of remaining on the GUI with the buttons. By using a pushbutton, I can have the status bar remain on the GUI but it stays filled instead of being synced with the change in text. When I have it synced, I have it part of the timer function callback, but it opens in another window. Can someone please help?

 채택된 답변

Geoff Hayes
Geoff Hayes 2016년 4월 4일

0 개 추천

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
% set the axes
cla(handles.axes1);
set(handles.axes1,'Visible','on','color',[.9 .85 .3]); %this will set the color of the patch
axis(handles.axes1,[0,1,0,1]); %show only from x=0to 1 and y=0to1
handles.hPatch = patch([0,0,0,0],[0,0,1,1],'g');
axis(handles.axes1, 'off'); %do not show axis bars
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 the progress timer
stop(handles.timerProgress);
% only set the progress timer to complete if there is text in pushbutton1
% we pause for half a second to allow the progress bar to update
if ~isempty(get(handles.pushbutton1,'String'))
set(handles.hPatch,'XData',[0 1 1 0]);
pause(0.5);
end
% etc.
% reset the patch to show zero progress
set(handles.hPatch,'XData',[0 0 0 0]);
% use tic so that we can correctly update the progress
tic;
% start the timer
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.)

댓글 수: 2

Justin
Justin 2016년 4월 9일
I decided not to use Guide for the GUI and instead used the other code that you helped me with. I did use your logic in this and the other times you helped me out. Thank you very much for all your help. I pretty much finished this GUI now.
Geoff Hayes
Geoff Hayes 2016년 4월 10일
Glad that I was able to help, Justin!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 App Building에 대해 자세히 알아보기

질문:

2016년 3월 31일

댓글:

2016년 4월 10일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by