필터 지우기
필터 지우기

Indexing animated lines from array

조회 수: 6 (최근 30일)
Koen
Koen 2020년 11월 19일
댓글: Koen 2020년 11월 19일
I would like to store multiple animatedline in one variable.
num_plots = 2;
for i = 1:num_plots
h(i) = animatedline;
end
makes this possible. However
h(1:num_plots) = animatedline;
does not work (points are concatenated, see code below).
for i = 1:100
for ih = 1:num_plots
x = i;
y = i*ih;
addpoints(g(ih),x,y)
end
end
Is there a way to avoid using a for loop?

채택된 답변

Ameer Hamza
Ameer Hamza 2020년 11월 19일
편집: Ameer Hamza 2020년 11월 19일
When you initialize an array of MATLAB graphics objects like this
num_plots = 2;
g(1:num_plots) = animatedline;
MATLAB creates a single instance of animatedline and assigns it to all elements. Since animatedline is a handle class, all elements of 'g' point to the same object
>> g(1)==g(2)
ans =
logical
1
The workaround is to use a for-loop to initialize so that each element is created independently. For a slightly easier syntax, you can use arrayfun()
num_plots = 2;
g = arrayfun(@(x) animatedline(), 1:num_plots);
for i = 1:100
for ih = 1:num_plots
x = i;
y = i*ih;
addpoints(g(ih),x,y)
end
end
  댓글 수: 1
Koen
Koen 2020년 11월 19일
Thank you very much for the explanation!

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

추가 답변 (0개)

카테고리

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

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by