你如何绘制随时间演变的图形?

时间:2016-04-26 19:59:13

标签: matlab graph

我有关于显示边缘和节点的网络数据,例如:

    edges = ...
    [5  7   1;
    5   7   2;
    5   11  2;
    5   7   3;
    5   11  3;
    5   16  3;
    5   7   4;
    5   11  4;
    5   16  4;
    5   21  4];

我想基于这些边缘如何进化而获得多个不同的图,因为这些边是长期观察的结果(例如一年)。

每个边缘都出现在不同的时刻,因此,我想分别得到这六个不同的情节。

假设,我看到这些边缘的第一个月:

    edges = ...
    [5  7   1];

在第二个月,我看到了:

    edges = ...
    [5  7   2;
    5   11  2;];

逐月,添加更多边缘,直到获得上面显示的完整数据集。

修改

第三列是时刻标识符并使​​用本文(Filter Matrix by some column value 我可以遍历矩阵并获得在graph()函数中使用的filtered_edges。

结束编辑

简单的方法是创建不同的边缘文件并逐个读取它们,但是有没有办法用Matlab以编程方式执行此操作?

1 个答案:

答案 0 :(得分:0)

有关详细信息,请参阅mathworks documentation。对于您的情况,请转到:

data = rand(6,2);

figure
% You need to somehow fix your axes, so that they don't resize
axis tight manual
ax = gca;
ax.NextPlot = 'replaceChildren';


% Let's record this to file
v = VideoWriter('myAnimation.avi');
v.FrameRate = 10; % slow down the animation
open(v);

loops = size(data,1);
F(loops) = struct('cdata',[],'colormap',[]); % Struct to hold frames

for i = 1:loops
    plot(data(1:i,1),data(1:i,2),'*'); % plot what you want in the new frame
    drawnow % clear and draw new frame
    frame = getframe;

    F(i) = frame; % if you want to animate locally you only need this
    pause(0.1); % this just slows down locally, can be removed and does NOT influence the saved video

    writeVideo(v,frame); % this is only if you want to save to file
end
close(v);