sgtitle drawing overtop of previous title

41 views (last 30 days)
Elliot Hall
Elliot Hall on 21 Nov 2018
Commented: David Franco on 31 Dec 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.

Answers (1)

Morgan Henderson
Morgan Henderson on 27 Nov 2018
The trouble is that every time the function sgtitle is called, it creates a new 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:
figtitle = sgtitle('some initial title');
for i=1:100
newfigtitle = ['new title #',num2str(i)];
figtitle.String = newfigtitle;
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 Comment
David Franco
David Franco on 31 Dec 2018
I always get confused by these commands: drawnow and cla.

Sign in to comment.





Community Treasure Hunt

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

Start Hunting!