Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

To resolve issues starting MATLAB on Mac OS X 10.10 (Yosemite) visit: http://www.mathworks.com/matlabcentral/answers/159016

Passing handles through guidata

Asked by Kjell on 15 Feb 2013

Hello all,

I am having an issue passing data through callbacks in my interface. What is happening is when I press a button on my interface, it changes two handle subvariables. What we see is:

handles.stopFlag = 1;
handles.running = 0;
guidata(hObject, handles);

Above is an excerpt from the end of the my button callback function. Usually this button is pressed when a while loop is running in another function. When the function returns, it is always returning after a drawnow function followed by a guidata(hObject,handles) function as seen below.

drawnow;                        
guidata(hObject,handles);

So my issue is that after the button is pressed and in the button callback, the variables in the handle structure are correctly valued: handles.stopFlag = 1 and handles.running = 0, but when I enter back into the while loop, these value are not see by the program because the guidata(hObject,handles) is overwriting this change before it can take effect.

Now I am not quite sure what to do here because I don't have much experience with GUIs or GUIDE but I have been trying to exclude the guidata function or only use update using certain parts of the handles structure.

Does anyone have any idea for me to try out? All are appreciated! Thanks!

0 Comments

Kjell

Products

No products are associated with this question.

1 Answer

Answer by Walter Roberson on 15 Feb 2013
Accepted answer

Instead of

drawnow;                        
guidata(hObject,handles);

use

drawnow;
handles = guidata(hObject);

1 Comment

Kjell on 18 Feb 2013

That worked perfectly. Thank you for your help!!! That is so much better of a solution than using global variables :P

Walter Roberson

Contact us