Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: stop/pause plot signal with toggle button
Replies: 8   Last Post: Mar 26, 2013 4:37 PM

 Messages: [ Previous | Next ]
 Nasser Abbasi Posts: 6,677 Registered: 2/7/05
Re: stop/pause plot signal with toggle button
Posted: Mar 26, 2013 5:34 AM

On 3/26/2013 4:17 AM, Nasser M. Abbasi wrote:
> On 3/26/2013 3:32 AM, zack00 wrote:
>> Hi
>> I have a 2 axes in my GUI with 2 different running signals..and 2 toggle buttons
>>
>> If toggle button = 1 signal is running and plotting...and if toggle
>> button = 0 i want to stop/pause plotting this signal..and it is a problem for me
>>
>> How can I do it?
>>
>>

>
> May be you use a call back to flip which plot to make?
>
> something like this:
>

This version uses 2 axes instead of one. (just noticed you
wanted 2 axes)

---------------------------------------
function foo()

stopIt = false;
signalToPlot = 0;
t = 0:.2:4*pi;
N = length(t);
k1 =0;
k2 =0;

set(0,'Units','Normalized');
f=figure('Units','normalized','Position',[.3 .3 .42 .42]);
h1=axes('Parent',f,'Units','normalized','Position',[.1 .2 .30 .6]);
h2=axes('Parent',f,'Units','normalized','Position',[.5 .2 .30 .6]);
h1Btn=uicontrol('Units','Normalized','Parent',f,...
'Style', 'pushbutton',...
'Position', [.05 .05 .1 .1],...
'String','toggle',...
'Callback', @btn1Callback,'FontSize',12);
h2Btn=uicontrol('Units','Normalized','Parent',f,...
'Style', 'pushbutton',...
'Position', [.15 .05 .1 .1],...
'String','quit',...
'Callback', @btn2Callback,'FontSize',12);

while not(stopIt)

if signalToPlot
k1 = mod(k1+1,N);
set(f,'CurrentAxes',h1);
plot(t(1:k1),sin(t(1:k1)),'r.-');
title('sin(x)');
else
k2 = mod(k2+1,N);
set(f,'CurrentAxes',h2);
plot(t(1:k2),cos(t(1:k2)),'k.-');
title('cos(x)');
end
xlim([0 4*pi]);
ylim([-1.1 1.1]);
grid;

drawnow;
pause(.1);
end

function btn1Callback(hObject,eventdata)
signalToPlot = not(signalToPlot);
end

function btn2Callback(hObject,eventdata)
stopIt=true;
end

close all;
end
---------------------

Date Subject Author
3/26/13 zack00
3/26/13 Nasser Abbasi
3/26/13 Nasser Abbasi
3/26/13 zack00
3/26/13 Nasser Abbasi
3/26/13 zack00
3/26/13 zack00
3/26/13 Nasser Abbasi
3/26/13 zack00