MATLAB Answers

How to add animatedline to formatted figure?

2 ビュー (過去 30 日間)
arianne ford
arianne ford 2021 年 3 月 24 日
コメント済み: arianne ford 2021 年 3 月 25 日
Hi all,
I am trying to get an animated line to plot on an already formatted figure. Simplified code below:
xlabel ('x');
ylabel ('y');
axis ([0 10000 0 10]);
grid on;
title('my plot', 12);
myline1 = animatedline('Color', 'r');
a = 0;
b = 1000000;
while a<b
x1 = somevalue;
y1 = someothervalue;
set(0, 'CurrentFigure', 1);
addpoints(myline1, x1, y1)
a = a+1;
However what I'm getting from this is a nicely formatted figure with the axis titles and the range of values but empty of data points, and the animatedline plotting in another figure window. How can I get the animated line to plot onto the existing figure with the required formatting?
The code outputs the correct values for x1 and y1, it's just the plot that I'm struggling with.
Apologies if I'm missing the obvious, this is the first time I've used Matlab in nearly 20 years. Trying to relearn!
Would appreciate any advice.


Les Beckham
Les Beckham 2021 年 3 月 25 日
From what you have posted, you have explicitly requested a new figure with the line:
This will create a new figure and subsequent plotting commands will put their output into this new figure, not any previously created figure.
Consider removing the figure() line and replacing by
hold on
It also sounds like you are having issues with the "nicely formatted figure" since you say it is "empty of data points".
If you wish to get help with that you will need to post the code that you are using to create that as well.
  1 件のコメント
arianne ford
arianne ford 2021 年 3 月 25 日
I think I have it functioning now. The domain I was using for the y-axis was insufficient. Increased it by a few orders of magnitude and now I can see the line.
Thanks for the tip regardless!


その他の回答 (0 件)




Community Treasure Hunt

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

Start Hunting!

Translated by