sgtitle drawing overtop of previous title
41 views (last 30 days)
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.
Morgan Henderson on 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:
figtitle = sgtitle('some initial title');
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.