Date: Mar 26, 2013 6:43 AM
Author: Nasser Abbasi
Subject: Re: stop/pause plot signal with toggle button

On 3/26/2013 5:23 AM, zack00 wrote:
> thanks for help..second choice is good, but i want to stop and
>start first axe or second axe independently
>



Just add another button and separate flags to control each axes on its own.
The idea is the same. Using callbacks and some state flag you can
make any logic you want.

something like

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

stopIt = false;
signal1ToPlot = 1;
signal2ToPlot = 1;
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', [.15 .05 .1 .1],...
'String','toggle',...
'Callback', @btn1Callback,'FontSize',12);
h2Btn=uicontrol('Units','Normalized','Parent',f,...
'Style', 'pushbutton',...
'Position', [.55 .05 .1 .1],...
'String','toggle',...
'Callback', @btn2Callback,'FontSize',12);

h3Btn=uicontrol('Units','Normalized','Parent',f,...
'Style', 'pushbutton',...
'Position', [.8 .05 .1 .1],...
'String','quit',...
'Callback', @btn3Callback,'FontSize',12);

while not(stopIt)

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

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


drawnow;
pause(.1);
end

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

function btn2Callback(hObject,eventdata)
signal2ToPlot = not(signal2ToPlot);
end

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

close all;
end

----------------------
--Nasser