Sharing variable between GUIDE callback functions
1 回表示 (過去 30 日間)
古いコメントを表示
Hi,
I have two callback functions that are called by two different buttons. The user presses one button and the first callback function starts. This function takes a long time to execute and I want to periodically check a variable in the guidata to see if the user has pressed the second button, which indicates that the user wants to stop. In the second button, the function just updates the variable. Unfortunately, the first function does not seem to see the updated value. Here is an example (I took out the extra code that is not necessary).
% gui initialization handles.stopped = 0; guidata(hObject,handles);
function pushbutton1_KeyPressFcn(hObject, eventdata)
cont = 1; while cont == 1 handles = guidata(hObject); handles.stopped if handles.stopped == 1 cont = 0; else % do long processing end end
function pushbutton2_KeyPressFcn(hObject, eventdata) handles.stopped = 1 guidata(hObject,handles);
I can see on the command window that handles.stopped = 1 is executed but in the first function, the handles.stopped line continues to be evaluated as 0 (as seen in the command window).
Is there a better way to share data between these two callbacks. I searched and saw some information on nested callbacks but in this case both callbacks are on the same level and independently called by the user. I also tried a global variable declared in the initialization function and the two callbacks, but the same thing happened. I thought that having the line handles = guidata(hObject) in the first callback would allow me to get refreshed data, but it doesn't seem to be working.
0 件のコメント
回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Migrate GUIDE Apps についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!