Hello MATLAB family,
I am new user of GUI, so not familier with GUI. I have question regarding Stop button. I made one GUI which has Start Measurement and Stop Measurement buttons. From start button I can succesfully start my program, but I don't have any idea how can stop the running program.
Idea behind code is when I press the start button program takes picture one-by-one upto 200 pic. but I want one stop button when I press that button, My program will be stop.

 Akzeptierte Antwort

Rik
Rik am 15 Jul. 2021
Bearbeitet: Rik am 15 Jul. 2021

0 Stimmen

The general solution is to have the stop button set a flag (either in the guidata or in the UserData property of an object).
%in your looping code
set(handles.StopButton,'UserData',false)
for picture=1:2000
drawnow
if get(handles.StopButton,'UserData')
break
end
end
%in your button callback:
function StopButtonCallback(obj,event)
set(obj,'UserData',true)
end

5 Kommentare

Kishan Paladiya
Kishan Paladiya am 15 Jul. 2021
Thank you for this suggestion but nothing happens with this code. Pic capturing still in progress.
Rik
Rik am 15 Jul. 2021
Did you set a breakpoint to follow the execution of your code?
What you could do as well, is print the value of the UserData to the command window. That way you can see the actual current value. And see if it indeed changes to true when you click the button.
If you do that, you will notice a bug in my answer: the callback set the value to false instead of true.
Kishan Paladiya
Kishan Paladiya am 15 Jul. 2021
if you can help me via email then it's good form me. kpaladiya@gmail.com
this is my email could you please sne dme an email so I will show you my progress GUI.
Rik
Rik am 15 Jul. 2021
I prefer keeping the discussion public, so others can learn from this as well. If I send you an email, I can help only 1 person, while if the discussion happens here, I can potententially help many more.
Have you made the edit to my answer (replacing 'false' in the callback with 'true')? If you did, did you try my other suggestions to try to determine why the callback is ignored, even with the call to drawnow?
Kishan Paladiya
Kishan Paladiya am 16 Jul. 2021
Now whole this is work propely, Thanks buddy for this solution. I appreciate and got satisfactory answer.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Interactive Control and Callbacks finden Sie in Hilfe-Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by