필터 지우기
필터 지우기

how can i have a button in one callback function pause the execution of another callback function

조회 수: 3 (최근 30일)
function pushbutton1_Callback(hObject, eventdata, handles)
%when this button is pressed i want the code that is executing in
%pushbutton2 to pause
end
function pushbutton2_Callback(hObject, eventdata, handles)
%some code
end
%i am using matlab version R2019b
%Thank you
  댓글 수: 1
Adam Danz
Adam Danz 2021년 5월 27일
편집: Adam Danz 2021년 5월 27일
@Joseph Kutteh this question doesn't differ much from the question you asked earlier this week and never replied to:
And it's no surprise that both questions describe the same solution with some minor differences.
How many people do you want working on your problem? Please take some time to learn from the solutions and if you've got follow-up questions, leave comments.

댓글을 달려면 로그인하십시오.

채택된 답변

Jan
Jan 2021년 5월 27일
편집: Jan 2021년 6월 1일
% Initialize in the CreateFcn: handles.Pause = false
function pushbutton1_Callback(hObject, eventdata, handles)
handles.Pause = (hObject.Value == 0);
guidata(hObject, handles);
end
function pushbutton2_Callback(hObject, eventdata, handles)
for k = 1:1000
disp(clock); % <-- This is the pseudo code
pause(0.5); % <-- Insert your real computations instead
% If button1 was pressed, stay in this loop:
while handles.Pause % [EDITED] WHILE instead of IF ?!
handles = guidata(hObject);
pause(0.2);
end
end
end
  댓글 수: 3
Jan
Jan 2021년 6월 1일
I do not understand, what you are asking for. I've marked the dummy lines now, which I have inserted instead of the real computations.
Adam Danz
Adam Danz 2021년 6월 1일
편집: Adam Danz 2021년 6월 1일
The while loop in Jan's answer 'pauses' execution if the pause-flag is set to true. This flag is set by pressing pushbutton1 which must be a togglebutton that has a binary state (on/off) (see the pushbutton1_Callback function in Jan's answer).
Note that execution isn't really paused. It's just stuck in the while loop until it gets the signal to escape.
Before you sink too much time into a GUI that appears to be created by GUIDE, note that,
>The GUIDE environment will be removed in a future release. After GUIDE is removed, existing GUIDE apps will continue to run in MATLAB® but they will not be editable in GUIDE - noted in r2021 documentation.
Other ways to implement pauses in Apps/GUIs.
  • waitfor - example using AppDesigner but can be implemented outside of AppDesigner, too.
  • uiprogressdlg with the Indeterminate option (requires uifigure which excludes GUIDE GUIs)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by