How to add animatedline to formatted figure?

2 vues (au cours des 30 derniers jours)
arianne ford
arianne ford le 24 Mar 2021
Commenté : arianne ford le 25 Mar 2021
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.

Réponse acceptée

Les Beckham
Les Beckham le 25 Mar 2021
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 commentaire
arianne ford
arianne ford le 25 Mar 2021
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!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Animation dans Help Center et File Exchange

Produits


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by