this is what i mean by running in the GUI
Pause button for GUI
조회 수: 7 (최근 30일)
이전 댓글 표시
Hi,
My gui runs a plotting fucntion i created for some txt data. with a start, pause and stop button, i dont know how to make the while loop for it to stop but,
I am using the following for a pause button, it works , however when i press it it continues to run the called function on the actual gui. Is there a way to stop that?
% --- Executes on button press in Pause.
function Pause_Callback(hObject, eventdata, handles)
% hObject handle to Pause (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
set(gcbo,'userdata',1)
% --- Executes on key press with focus on Start and none of its controls.
function Start_KeyPressFcn(hObject, eventdata, handles)
% hObject handle to Start (see GCBO)
% eventdata structure with the following fields (see MATLAB.UI.CONTROL.UICONTROL)
% Key: name of the key that was pressed, in lower case
% Character: character interpretation of the key(s) that was pressed
% Modifier: name(s) of the modifier key(s) (i.e., control, shift) pressed
% handles structure with handles and user data (see GUIDATA)
% function browse_data()
% [filename, pathname] = uigetfile('.txt');
% set( yourEditHandle, 'String', filename);
%
i=1;
while i
drawnow
if get(handlepushbutton,'userdata'); % stop condition
break;
end
i=i+1;
end
댓글 수: 3
답변 (1개)
Alex Mcaulley
2019년 5월 27일
Following your code, for example (The property 'Interruptible' of the start button must be set to 'on'):
% --- Executes on button press in Pause.
function Pause_Callback(hObject, eventdata, handles)
% hObject handle to Pause (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
if isempty(get(hObject,'UserData'))
set(hObject,'UserData',1)
else
set(hObject,'UserData',~get(hObject,'UserData'))
end
guidata(hObject, handles);
% --- Executes on key press with focus on Start and none of its controls.
function Start_KeyPressFcn(hObject, eventdata, handles)
% hObject handle to Start (see GCBO)
% eventdata structure with the following fields (see MATLAB.UI.CONTROL.UICONTROL)
% Key: name of the key that was pressed, in lower case
% Character: character interpretation of the key(s) that was pressed
% Modifier: name(s) of the modifier key(s) (i.e., control, shift) pressed
% handles structure with handles and user data (see GUIDATA)
% function browse_data()
% [filename, pathname] = uigetfile('.txt');
% set( yourEditHandle, 'String', filename);
%
i=1;
while i
drawnow
if get(handles.waitPushButton,'UserData'); % stop condition
waitfor(handles.waitPushButton,'Value',0) %Waits for another click on wait pushbutton
end
i=i+1;
end
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Creating, Deleting, and Querying Graphics Objects에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!