How do I do multi animated lines in one axes?

조회 수: 89 (최근 30일)
ren ren
ren ren 2016년 8월 30일
댓글: Koen 2020년 11월 17일
I need to do two multi animated lines in one axes.Is there any solution to this problem? As picture shows: This picture use "plot" ,but It's slowly when close to the end. And the matlab give a suggestion :use animatline to instead the plot function.

채택된 답변

Thorsten
Thorsten 2016년 8월 30일
편집: Thorsten 2016년 8월 30일
Just create a second animatedline and use addpoints:
numpoints = 100000;
x = linspace(0,4*pi,numpoints);
y = sin(x);
y2 = cos(x);
figure
h = animatedline;
h2 = animatedline;
axis([0,4*pi,-1,1])
for k = 1:numpoints
addpoints(h,x(k),y(k))
addpoints(h2,x(k),y2(k))
drawnow update
end
  댓글 수: 4
Walter Roberson
Walter Roberson 2020년 8월 16일
saveas() or print()
Or getframe() and imwrite() the data part of it.
Koen
Koen 2020년 11월 17일
I want to add animatedlines programmatically rather than using h1, h2, h3... (number of lines depends on certain input arguments in code)
h(1:num_lines) = animatedline
creates an animatedline array. I'm trying to access these in a loop where data is updated by doing something like
for x = 1:10
for i = 1:num_lines
y = i*x;
addpoints(h(i),x,y)
end
end
Intuitively, I would expect this code to create straight lines with different slopes. However this does not seem to work this way: it creates a single line (instead of num_lines), concatenating values h(1:num_lines). Is it possible to use animatedline in a similar way; using indices to feed data?

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

추가 답변 (2개)

Le Dung
Le Dung 2017년 12월 15일
편집: Le Dung 2017년 12월 15일
I suggest to you another approach, i think it is familiar to anyone. You can use "hold on" after "figure" And, of course, at the moment, "update" in "drawnow is no need. I will use example that Thorsten is given. Of course, to reduce cost time, i use 1000 to replace for 100000.
numpoints = 1000;
x = linspace(0,4*pi,numpoints);
y = sin(x);
y2 = cos(x);
figure
hold on % To hold this figure.
h = animatedline;
h2 = animatedline;
axis([0,4*pi,-1,1])
for k = 1:numpoints
addpoints(h,x(k),y(k))
addpoints(h2,x(k),y2(k))
drawnow % "update" is no need for this case
end

vlad gnatenko
vlad gnatenko 2018년 12월 23일
What if u need 2 lines in 2 Figures?

카테고리

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