how to grab text from figure's suptitle and subplot titles
32 ビュー (過去 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!