how to grab text from figure's suptitle and subplot titles
22 views (last 30 days)
Show older comments
I'm familiar with how to grab the title from a simple figure such as this:
htitle = get(gca,'Title');
stitle = htitle.String
This works sufficient for a simple plot/title, but when a figure has subplots (each with a title) and a "suptitle" title on top, the function above seems to grab a title I don't want.
1) How do I specifically grab the suptitle text?
2) How do I grab the title text from say subplot(2,2,1)?
Thank you for your help!
0 Comments
Answers (1)
Kevin Holly
on 21 Jan 2022
subplot(2,2,1)
plot(1:10,rand(1,10))
title('pick me');
subplot(2,2,2)
plot(1:10,rand(1,10))
title('not me');
subplot(2,2,3)
plot(1:10,rand(1,10))
title('not me');
subplot(2,2,4)
plot(1:10,rand(1,10))
title('not me');
sgtitle('Select me')
handle = gcf %obtain the handle of the figure (get current figure).
handle.Children %Look at the Children of the figure
handle.Children(1) %Select first child (the text of the sgtitle)
handle.Children(end) %Select the last child (the axes of subplot(2,2,1)
handle.Children(end).Title %Now select the title
handle.Children(end).Title.String %and now the string of the title
0 Comments
See Also
Categories
Find more on Subplots 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!