sgtitle drawing overtop of previous title
22 views (last 30 days)
Show older comments
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.
0 Comments
Answers (1)
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:
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 Comment
David Franco
on 31 Dec 2018
See Also
Categories
Find more on Line Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!