Breaking a loop GUI?

Reading in accelerometer data in a GUI code. I'm trying to break the loop while reading by using the following code...
function pushbutton8_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton8 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
a = getappdata(handles.text11, 'text11');
%COMPORT
comPort = '/dev/tty.usbmodemfd121';
%READS SERIAL
[accelerometer.s,serialFlag] = setupSerial(comPort);
calCo = calibrate(accelerometer.s);
%READS DATA
while (a == 0)
if (a == 1)
closeSerial
end
[gx gy gz] = readAcc(accelerometer,calCo);
cla;
r = sqrt((gx^2)+(gy^2)+(gz^2));
r
end
guidata(hObject, handles);
My problem is that the data keeps reading even when (a == 1), which is activated from a separate pushbutton. I've already tested the outputs of both each pushbuttons and they do read 0 and 1, but when reading the data, if I press the 1 pushbutton the data will still read.

댓글 수: 6

Amed
Amed 2013년 2월 11일
The part in question is under %READS DATA, i'm trying to run the accelerometer, UNLESS another pushbutton is pressed, which should make a == 1
Amed
Amed 2013년 2월 11일
Anybody have an idea?
Amed
Amed 2013년 2월 11일
hmm
Jan
Jan 2013년 2월 11일
@Amed: Please do not bump your question frequently. If the contributors do not know an answer, it does not help to read trhe question one hour later again, as long as no additional information is provided. Thanks.
Amed
Amed 2013년 2월 14일
^Sorry. Anybody else have ideas? I haven't bumped in two days.
Amed
Amed 2013년 2월 14일
Anybody? This is a major assignment help a brother out

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

답변 (1개)

Walter Roberson
Walter Roberson 2013년 2월 11일

0 개 추천

while true
drawnow;
a = getappdata(handles.text11, 'text11');
if a == 0; break; end
...
end

댓글 수: 2

Amed
Amed 2013년 2월 13일
Where in the code would I put this? Thanks
Jan
Jan 2013년 3월 11일
@Amed: Neither "oh ok" nor "anything" contains enough information to understand, if this answer has solved your problem or not. If you want help, provide more details instead of bumping the thread without new informations.

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

카테고리

도움말 센터File Exchange에서 MATLAB에 대해 자세히 알아보기

제품

질문:

2013년 2월 11일

Community Treasure Hunt

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

Start Hunting!

Translated by