How to allow a gui to run simultaneous tasks communicating between them?

1 view (last 30 days)
I am working on an application creating a scatterplot animation. The animation is based on a for loop. Inside this loop first the program erases then it plots points corresponding to the position of one or more accelerometors in the space. A GUI displays this. I have added buttons to pause or to stop the animation. These button communicate with the animation function by using global variables. But it doesn't work when the animation is to heavy, actually the press on one of the button is not take in account until the animation is finished.
Here is the code of the animation function:
global stop
global isPaused
for index_begining= tmin_row:tmax_row-1
cla(handles.signal_plot) %remove the previous points
hold (handles.signal_plot,'on') %keep axes' paramaters
%plot connector per connector
for i=1:nmb_connectors
for j=index_begining:i_end
plot3(handles.signal_plot, sig_matrix(j,3*a-2),sig_matrix(j,3*a-1)...
,sig_matrix(j,3*a),'Marker',sensors_data{a,7},'MarkerEdgeColor',...
sensors_data{a,8},'MarkerSize',sensors_data{a,9})
end
end
hold (handles.signal_plot,'off')
if isPaused==true
uiwait
elseif stop==true
cla(handles.signal_plot)
break
else
wt=str2double(get(handles.time_scale,'String')); %re-calculate each loop to can be changed during operation
pause(wt)
end
end
cla(handles.signal_plot)
The first for loop define the beginning and the end of the animation. The second loop deals with the number of "sensor" I want to plot. And the third loop allow to plot several points for one sensor.
The code in the button pause (a toggle button) is:
global isPaused
a=get(hObject,'Value');
if a==1
isPaused=true;
set(hObject,'String','Replay')
else
uiresume
isPaused=false;
set(hObject,'String','Pause')
end
clear a
and inside the button stop:
global stop
global isPaused
stop = true;
isPaused=false;
set(hObject,'BackgroundColor','r')
pause(2)
set(hObject,'BackgroundColor',[0.94 0.94 0.94])
As I said this works only if the animation is "light", few sensors, few points to plot per sensor. With an heavier animation, if I add a "disp('Stop')" inside the callback of a button, it appears when the animation is done. Stop or pause a finished animation is not very relevant. So if you have any idea to fix this I will appreciate a lot.
I am not sure it could be a solution but in any case I don't have the Parallel toolbox.
Is there a way to do a thread in Matlab on a computer having a single processor?

Answers (0)

Categories

Find more on Animation in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!