Clear Filters
Clear Filters

Putting plot title one only one line

48 views (last 30 days)
Collin Tuttle
Collin Tuttle on 28 Mar 2017
Answered: Star Strider on 28 Mar 2017
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?

Answers (1)

Star Strider
Star Strider on 28 Mar 2017
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

Tags

Products

Community Treasure Hunt

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

Start Hunting!