How do I show my output value from "Command Window" to "GUI".
MATLAB: How to Show output Value to GUI.
matlab gui
Related Solutions
mediumbtn_Callback(hObject, eventdata, handles)
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.)
Best Answer