How to click stop a function in while loop using a pushbotton in GUI?

I have two buttons. When DC_start is pressed it disables itself and two user inputs, and then enters a while loop. At some point the user will click the DC_end button and it changes its value to 1 and the while loop is supposed to break.
A simplified version of the code is provided below with the error. Please let me know how to overcome this as its my first time making a GUI. I believe I have to use the uiwait function and suppress the warning, but even then I am confused at how to use the handle for the DC_end button if its not in the scope of the DC_start callback function.
If there is a completely different but better way to code this up. I'm open to suggestions.
Thanks in advance, George
function DC_start_pushbutton1_Callback(hObject, eventdata, handles)
set(handles.DC_start_pushbutton1,'Enable', 'off')
set(handles.DC_numSamples_edit, 'Enable', 'off')
set(handles.DC_electrodesList_edit, 'Enable', 'off')
channelNum = 0;
dataEntry = 0;
endButton = get(handles.DC_end_pushbutton2,'Value');
while( ~isequal(endButton, 1))
endButton = get(handles.DC_end_pushbutton2,'Value');
channelNum = channelNum + 1; dataEntry = dataEntry + 1;
pause(0.500);
if endButton == 1;
disp('Data collection canceled!')
break;
end
end
disp('Done!');
function DC_end_pushbutton2_Callback(hObject, eventdata, handles)
set(handles.DC_end_pushbutton2,'Value',1)
Error Message:
Undefined function or variable 'ElectrodeGUI'.
Error in
@(hObject,eventdata)ElectrodeGUI('DC_end_pushbutton2_Callback',hObject,eventdata,guidata(hObject))
Error using pause
Error while evaluating UIControl Callback

 채택된 답변

kausalya
kausalya 2015년 6월 30일

0 개 추천

Hi George,
You could use uiwait instead of pause which would eliminate one error. To answer your second question, to access handles or data of a control when you are out of scope of that control, you can use findobj.
h = findobj('Tag','DC_end_pushbutton2'); %variable h has the handles of pushbutton2 and can be accessed anywhere. data = h.UserData; % For R2014a and earlier: % data = get(h,'UserData');
hope this helps.
Thanks

댓글 수: 2

Thanks a lot for the findobj help. If my pauses need to be under a second is there a workaround for the whole warning that uiwait throws up if your wait time is less than a second?
if you do not want to use uiwait then you could just use pause(1) which would pause for a sec.

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Creating, Deleting, and Querying Graphics Objects에 대해 자세히 알아보기

태그

질문:

2015년 6월 30일

댓글:

2015년 7월 2일

Community Treasure Hunt

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

Start Hunting!

Translated by