sgtitle drawing overtop of previous title

11 Ansichten (letzte 30 Tage)
Elliot Hall
Elliot Hall am 21 Nov. 2018
Kommentiert: David Franco am 31 Dez. 2018
I am attempting to change the title of a group of subplots using sgtitle after every iteration of a loop. Matlab, instead of replacing the subplot title text seems to draw over it with the new title.
I have used this technique with normal plot titles without a problem, the existing titles from the previous iteration are replaced and the new title for the current iteration are displayed.
Any help would be appreciated.

Antworten (1)

Morgan Henderson
Morgan Henderson am 27 Nov. 2018
The trouble is that every time the function sgtitle is called, it creates a new matlab.graphics.illustration.subplot.Text object, which then gets placed on your figure. To simply update the title at every step in your loop, call sgtitle before your loop and reassign its String property at every step. That looks like this:
figure()
figtitle = sgtitle('some initial title');
for i=1:100
newfigtitle = ['new title #',num2str(i)];
figtitle.String = newfigtitle;
drawnow
end
This way you can still leave your figure open throughout the loop and update only your subplots, which is what I'm guessing you're doing, rather than having to open and close a brand new figure with a brand new title at every step.
  1 Kommentar
David Franco
David Franco am 31 Dez. 2018
Perfect!
I always get confused by these commands: drawnow and cla.
Thanks!

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Tags

Produkte


Version

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by