How to use animated line

조회 수: 5 (최근 30일)
Kashfia Mahin
Kashfia Mahin 2019년 8월 27일
댓글: Kashfia Mahin 2019년 8월 27일
I want to use the animation in the piping network. this is a sample of a code:
s = [1 2 3];
t = [2 3 4];
G = graph(s,t);
h = plot(G);
The result of the figure is first.jpg
I want to an animation with this nework s that it can show creating edges from step by step like 1-->2, 2-->3 and so on. I build a code.
h=animatedline
s = [1 2 3];
t = [2 3 4];
axis([.5,3.5,-2,14])
for i=1:length(s)
g = graph(s(i),t(i));
p= plot(g);
drawnow
end
But the figure is untitled.jpg
i don't expect this figure. And also I don't know if the structure satisfies the animation mode or not.

채택된 답변

Kelly Kearney
Kelly Kearney 2019년 8월 27일
A couple notes here...
First, plotting a graph object creates a GraphPlot object, not a line, so it can't be used (out of the box) with animatedline. But you can get the same animated effect by looping like you've done in your example (it could be more efficient to update properties of the GraphPlot rather than redraw each time, but in this particular example the extra work isn't really worth it).
Second, if you don't specify the x/y coordinates of your graph nodes, the graph command chooses them based on certain properties of the graph. And those default x/y coordinates will change depending on the edges. Assuming you don't want that, you need to manually set the coordinates.
Finally, be careful how you're building your graphs. You want to preserve all the nodes, not just the ones with edges, I presume.
s = [1 2 3];
t = [2 3 4];
nnode = max([s t]);
x = ones(1,nnode);
y = 1:nnode;
g = graph(s,t);
axis([.5,3.5,-2,14]);
hold on;
for ii=1:length(s)
gplt = g;
gplt = rmedge(gplt, s(ii+1:end), t(ii+1:end));
if ii>1
delete(p);
end
p = plot(gplt, 'xdata', x, 'ydata', y, 'nodecolor', 'k', 'edgecolor', 'b');
drawnow
pause(1);
end
  댓글 수: 1
Kashfia Mahin
Kashfia Mahin 2019년 8월 27일
thank you so much

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Animation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by