Alex Zylman
Alex Zylman

Reputation: 920

Force matlab gui to update ui control mid-function

I'm working on a gui using GUIDE in MATLAB, and from what I've read it looks like MATLAB updates the UI controls based on a timer every so often. Is there a way to force it to update the UI controls, so I can make it update in the middle of the function? Right now I have a function that does, simplifed, something like

set(handles.lblStatus,'String','Processing...')
%function that takes a long time
set(handles.lblStatus,'String','Done')

Since MATLAB doesn't update the GUI during a Callback function, the user only ever sees 'Done' after a long period of waiting and never sees 'Processing'. I tried adding guidata(hObject, handles) after the first set, hoping it would force the screen to update, but it doesn't.

Upvotes: 10

Views: 7462

Answers (2)

neXus
neXus

Reputation: 2243

I believe there is a drawnow function in matlab.

drawnow completes pending drawing events

Upvotes: 0

Jonas
Jonas

Reputation: 74940

Try calling DRAWNOW.

set(handles.lblStatus,'String','Processing...')
drawnow
%function that takes a long time
set(handles.lblStatus,'String','Done')

Upvotes: 17

Related Questions