Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

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


Math Forum » Discussions » Software » comp.soft-sys.matlab

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

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Nasser Abbasi

Posts: 5,688
Registered: 2/7/05
Re: stop/pause plot signal with toggle button
Posted: Mar 26, 2013 5:17 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

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?
>
> thanks for answer
>


May be you use a call back to flip which plot to make?

something like this:

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

stopIt = false;
signalToPlot = 0;
t = 0:.2:12*pi;
N = length(t);
k =0;

set(0,'Units','Normalized');
f=figure('Units','normalized','Position',[.3 .3 .42 .42]);
h1=axes('Parent',f,'Units','normalized','Position',[.2 .2 .60 .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);
hold on;
xlim([0 12*pi]);
ylim([-1.1 1.1]);
grid;

while not(stopIt)
cla(h1);
k = mod(k+1,N);
if signalToPlot
plot(t(1:k),sin(t(1:k)),'r.-');
title('sin(x)');
else
plot(t(1:k),cos(t(1:k)),'k.-');
title('cos(x)');
end
pause(.1);
end

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

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

close all;
end

----------------------------



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.