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 Kommentare

Juan Palacios
Juan Palacios am 27 Mai 2019
this is what i mean by running in the GUI
Alex Mcaulley
Alex Mcaulley am 27 Mai 2019
take a look to:
Juan Palacios
Juan Palacios am 27 Mai 2019
where would i put this? in my while loop? and would i give it to wait for my executed function?

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Alex Mcaulley
Alex Mcaulley am 27 Mai 2019

0 Stimmen

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

Kategorien

Mehr zu Creating, Deleting, and Querying Graphics Objects finden Sie in Hilfe-Center und File Exchange

Produkte

Gefragt:

am 27 Mai 2019

Beantwortet:

am 27 Mai 2019

Community Treasure Hunt

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

Start Hunting!

Translated by