Clear Filters
Clear Filters

Pause and Play button for plotting

9 views (last 30 days)
Vick
Vick on 8 Nov 2017
Commented: Vick on 12 Nov 2017
Hi,
I'm having a data(ydata) of size 2000*2000, which has to be plotted in an axes one by one (given delay time as 0.5 sec) in gui axes when the user press the push button or toggle button(Play), the same has to be paused when it is pressed again(pause), How can it be done in a simplest way.
My current logic is,
ydata=rand(2000,2000);xdata=1:size(ydata,1); %random data
for i=handles.old_pause_data:size(ydata,2)
delay=str2num(get(handles.delaytime,'String')); % getting delay time from the edit text box
if get(handles.play_button,'Value')==1 % check to pause or play
plot(handles.axes1,xdata,ydata(:,i)) % plot the data
pause(delay) % delay for the given time
else
handles.old_pause_data=i; % save the pasued value.
break
end
end
guidata(hObject,handles)
The above code is bit complicated, I thought like it can be done easily.
Also I would like to change the toggle button to Play and Pause icon.
  2 Comments
Rik
Rik on 8 Nov 2017
Changing the icon should be done in the callback of the button itself. The code you have is not overly complicated, although correctly aligning it (in Matlab) will help. Be aware that sometimes you will need to call drawnow to execute queued button callbacks. If the pause is long enough (which it generally is), an extra drawnow is not needed.
Vick
Vick on 12 Nov 2017
Hi,
Thanks for the drawnow function, will help during my program...

Sign in to comment.

Answers (0)

Categories

Find more on Environment and Settings in Help Center and File Exchange

Tags

Products

Community Treasure Hunt

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

Start Hunting!