how to grab text from figure's suptitle and subplot titles
조회 수: 22 (최근 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!