0
votes

I have a timeseries I call x_matrix that is 45x100 as in 45 variables at 100 different time steps. I wrote a function I call plot_network that takes any column of x_matrix and plots a directed Graph in a figure. I would like to plot all time steps one after the other so I try this:

for t=1:length(x_matrix)
    plot_network(x_matrix,t)
end

However since the plot_network includes these lines:

figure
p  = plot(G)

G being the graph I build with edges from data in x_matrix (unrelated to this question)

The above for loop gives me 100 figures, I would like to have just one figure but the plot gets updated. As in an animation where the first time step is plotted then deleted from the figure and the following time step gets plotted in the same figure.

Any help is appreciated!

1
Take a look at this little example. The key for good animation is to access the relevant property in the figure/plot and update only it. In your case, I would plot the first graph outside the loop, and then get a handle to the data in the graph and change it. plot_network should either get a handle of axes data to update or output the data to be updated in the graph. - EBH

1 Answers

0
votes

Edit: Updated answer based on mb567's comment.

Put the figure command outside the plot_network function:

figure
for t=1:length(x_matrix)
    plot_network(x_matrix,t)
end

You can also add a 'pause(time_in_seconds)' if you want it to play as a video.