MATLAB Answers

Have separate push button stop while loop executed by another push button

1 view (last 30 days)
Dc215905
Dc215905 on 3 Nov 2017
Hello,
I have a GUI that starts data collection through a while loop and I would like to have a push button that 'breaks.'
My Data collection push button is as follows:
if true
function start_Callback(hObject, eventdata, handles)
handles.stop = 1;
tic
while toc<duration
if handles.stop==0;
break
end
tc = toc;
%Tracker 0
s1=analogin_mod(0,handles.phid);
s1 = 100.*(s1-s1min)./(s1max-s1min);
%(Insert Moving Average) s1v=[s1 s1v(1:2)];
%Tracker 2
s2=analogin_mod(1,handles.phid);
s2 = 100.*(s2-s2min)./(s2max-s2min);
%(Insert Moving Average)s2v=[s2 s2v(1:2)];
%SineWave
tNew=[tc-2:0.05:tc+3];
yNew=interp1(handles.x,handles.y,tNew);
plot(tNew,yNew,'-k','LineWidth',5);
xlim([tc-2 tc+3]);
ylim([-10 110]);
hold on
%Plot Trackers
plot(tc,s1,'-r.','MarkerSize',50);
plot(tc,s2,'-b.','MarkerSize',30);
drawnow;
hold off;
%CompileData
tall(end+1)=toc;
s1all(end+1)=s1;
s2all(end+1)=s2;
Track(end+1)=yNew(21);
end
data = [Track;tall;s1all;s2all]';
assignin('base','data',data);
end
I've tried to define 'stop' and then in the while loop have an 'if' statement that will break the loop if stop changes values.
my second push button is as follows:
if true
function stop_Callback(hObject, eventdata, handles)
handles.stop =0;
end
My hope is that if I push the 'Stop' button then stop will change in the first button to == 0 and therefore the while loop will break.
Can anyone help? Also, is there a better/easier way of achieving this effect?
Thanks

Answers (0)

Community Treasure Hunt

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

Start Hunting!