Pause button for GUI

17 次查看(过去 30 天)
Juan Palacios
Juan Palacios 2019-5-27
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 个评论
Juan Palacios
Juan Palacios 2019-5-27
where would i put this? in my while loop? and would i give it to wait for my executed function?

请先登录,再进行评论。

回答(1 个)

Alex Mcaulley
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

类别

Help CenterFile 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!

Translated by