| fc_animate(activ, activLabels, netLabels, circularPositions, circular_plot_axes, delay)
|
function [plot_coords movieMatrix] = fc_animate(activ, activLabels, netLabels, circularPositions, circular_plot_axes, delay)
% Animate the activation data in matrix 'actv' by plotting green circles on
% the circular connectivity plot for active nodes, red circes for inactive
% nodes, waiting for time delay 'delay' before plotting each successive row
% of activ. Nodes selected for removal will never be plotted as active.
% Also return a 'movieMatrix' which can be later saved as a .avi
% Make slider and editbox invisible so that user cannot adjust during
% animation
set(findobj('tag', 'animation_slider'), 'visible', 'off');
set(findobj('tag', 'animation_frame_editbox'), 'visible', 'off');
[noOfTimeSteps, noOfNodes_withRemovals] = size(activ);
if noOfTimeSteps == 0 | noOfNodes_withRemovals == 0
errordlg('Error - nothing to simulate!')
return;
end
noOfNodes = length(netLabels);
axes(circular_plot_axes);
hold on;
%---------------------------------------
% Make a numeric array plot_coords which is a copy of circularPositions
% (indicates x y positions of ALL nodes on circular graph), but with nodes
% selected for removal removed.
plot_coords = [];
for nodeCounter = 1 : noOfNodes
% If the node in netLabels is also present in activLabels (i.e. if
% it hasn't been REMOVED
if ~isempty(strmatch(netLabels{nodeCounter}, activLabels, 'exact'))
plot_coords(end+1, :) = circularPositions(nodeCounter, :);
end
end
%-------------------------------------------
%-------------------------------------------
% Plot
for timeStepCounter = 1 : noOfTimeSteps
for nodeCounter = 1: noOfNodes_withRemovals
if activ(timeStepCounter, nodeCounter) == 0
plot(plot_coords(nodeCounter,1), plot_coords(nodeCounter,2), 'r.', 'markerSize', 20);
else
plot(plot_coords(nodeCounter,1), plot_coords(nodeCounter,2),'g.', 'markerSize', 20);
end
end
% Make a movie frame
movieMatrix(timeStepCounter) = getframe(circular_plot_axes);
% Delay
delayTimer = timer('StartDelay', delay / 1000, 'TimerFcn', 'a=1;'); % NOTE: for some insane reason you HAVE to specify some callback function - a=1 is just a dummy!
start(delayTimer);
wait(delayTimer);
end
hold off;
set(findobj('tag', 'animation_frame_label'), 'visible', 'on');
set(findobj('tag', 'animation_frame_editbox'), 'visible', 'on');
set(findobj('tag', 'animation_slider'), 'visible', 'on');
return
|
|