Handles not getting updated from pushbutton using GUIDE
古いコメントを表示
Hello Everyone,
For my own understanding, I am trying to create a simple counter GUI with 2 pushbuttons namely 'Start counting' and 'Stop counting'
Start counting - Starts the counter
Stop counting - Stops the counter
I am having troubles to Stop the running counter using the Stop pushbutton. For some reason the handles.stop which gets set to 1 in the StopCounter_Callback does not reflect in the StartCounter_Callback.
Here is the piece of code.
Any help will be much appreciated. Thanks in advance.
function StartCounter_Callback(hObject, eventdata, handles)
counter = 0;
handles.start = 1;
while (1)
guidata(hObject, handles);
if (handles.stop == 0)
counter = counter + 1;
myString = sprintf('Value is %d', counter);
set(handles.text1, 'String', myString);
drawnow;
pause(0.1);
else
% Reset the Start & Stop button
handles.stop = 0;
handles.start = 0;
return;
end
end
% --- Executes on button press in StopCounter.
function StopCounter_Callback(hObject, eventdata, handles)
if(handles.start == 1)
handles.stop = 1;
end
guidata(hObject, handles);
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Programming についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!