How to add a title for any subplot in addition to a subplot title?

조회 수: 5 (최근 30일)
Let's assume I want to plot a few series using subplot:
x = randn(20,12);
for i = 1:size(x,2)
subplot(3,4,i)
plot(x(:,i),'-k')
title('Title')
end
Now, I want to add a title for each of the three rows. I only manage to display one for the first row as follows:
sgtitle('Title row I')
for i = 1:size(x,2)
subplot(3,4,i)
plot(x(:,i),'-k')
title('Title')
end
How can I add an "sgtitle" for every new row?
Thanks!

채택된 답변

Dave B
Dave B 2021년 8월 9일
You can do this sort of thing with tiledlayout instead of subplot, taking advantage of nested layouts:
t = tiledlayout(3,1); % tiledlayout to hold other tiledlayouts
for i = 1:3
tt = tiledlayout(t,1,4);
tt.Layout.Tile=i;
for ii = 1:4
nexttile(tt)
plot(rand(10,1))
title('axes title')
end
title(tt,sprintf('Row %d Title', i),'FontSize',11)
end
title(t,'Master Title')

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Title에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by