How to add animatedline to formatted figure?

3 次查看(过去 30 天)
Hi all,
I am trying to get an animated line to plot on an already formatted figure. Simplified code below:
figure();
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)
drawnow
a = a+1;
end
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:
figure();
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 个)

类别

Help CenterFile Exchange 中查找有关 Animation 的更多信息

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by