how to grab text from figure's suptitle and subplot titles
23 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Kevin Holly
2022-1-21
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Subplots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!