フィルターのクリア

Putting plot title one only one line

49 ビュー (過去 30 日間)
Collin Tuttle
Collin Tuttle 2017 年 3 月 28 日
回答済み: Star Strider 2017 年 3 月 28 日
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 Center および File ExchangeAnnotations についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by