Putting plot title one only one line

48 次查看(过去 30 天)
I am trying to run the following code:
t = datetime(2006, 01, 01):calmonths(1):datetime(2100, 12, 01);
x = 1:100;
y = 1:100;
for i = 1:12
subplot(6,2,i)
plot(x*i,y)
title(['It is ' month(t(i), 'name')])
end
But the title is forced onto a second line, does anyone know how to keep it on only one line?

回答(1 个)

Star Strider
Star Strider 2017-3-28
With a couple of tweaks, your code works as you want it to:
t = datetime(2006, 01, 01):calmonths(1):datetime(2100, 12, 01);
x = 1:100;
y = 1:100;
for i = 1:12
subplot(6,2,i)
plot(x*i,y)
m = month(t(i),'name'); % Isolate Month Name
title(sprintf('It is %s', m{:})) % Use ‘sprintf’
end

类别

Help CenterFile Exchange 中查找有关 Annotations 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by