Azzera filtri
Azzera filtri

Putting plot title one only one line

48 visualizzazioni (ultimi 30 giorni)
Collin Tuttle
Collin Tuttle il 28 Mar 2017
Risposto: Star Strider il 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?

Risposte (1)

Star Strider
Star Strider il 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

Tag

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by