How can I put a display that shows changing variables in a plot?

40 vues (au cours des 30 derniers jours)
Carlos Alan Parra Amaya
Carlos Alan Parra Amaya le 5 Déc 2019
Modifié(e) : Adam Danz le 10 Déc 2019
I wanted to know if I could put a display that shows me a number that changes in a plot.

Réponses (2)

Aquatris
Aquatris le 5 Déc 2019
Assuming you plot in a for loop and the changing variable is x, below code will update the title of the plot to be equal to x
for i = 1:length(x)
plot(t,x(i))
title(x(i))
pause(0.001)
end

Adam Danz
Adam Danz le 5 Déc 2019
Modifié(e) : Adam Danz le 10 Déc 2019
Use h=text(. . .) to create the text object and then update the handle as needed.
Here's a demo
clf()
axh = axes();
h = text(.5, .5, ''); % initialize as empty
for i = 1:15
h.String = i;
pause(.5)
end
You may want to format your numeric input using
h.String = sprintf(. . .);

Catégories

En savoir plus sur Formatting and Annotation dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by