MATLAB Answers

How do I add a title to each subplot?

5.519 views (last 30 days)
marie
marie on 13 Mar 2013
Commented: Chad Greene on 5 Apr 2019
I have the following codes
delta=[-2*pi:0.063:2*pi];
y=sin(delta);
subplot(3,2,1)
plot(y)
y=cos(delta);
subplot(3,2,2)
plot(y)
title(sin(delta))
My question is how do i put the title for each graph and labels? i tried to to do title(sin(delta)) but it doesn't show

  0 Comments

Sign in to comment.

Accepted Answer

Image Analyst
Image Analyst on 13 Mar 2013
Edited: MathWorks Support Team on 27 Nov 2018
Put the title commands after the plot and before the next subplot. Specify the title as a character vector or string scalar.
delta=[-2*pi:0.063:2*pi];
y=sin(delta);
subplot(3,2,1)
plot(y)
title('sin(delta)')
y=cos(delta);
subplot(3,2,2)
plot(y)
title('cos(delta)')

  0 Comments

Sign in to comment.

More Answers (2)

Chad Greene
Chad Greene on 28 Apr 2016
For subplots I often prefer to use ntitle rather than title. The difference is ntitle keeps the text closer to the data, whereas title places the text high above the axes, where it may appear to be an xlabel for to the plot above.

  0 Comments

Sign in to comment.


Azzi Abdelmalek
Azzi Abdelmalek on 13 Mar 2013
title('sin(delta)')

  2 Comments

Shakir Hussain
Shakir Hussain on 29 Mar 2019
Great Azzi
You are always providing short,simple and effective solution
thankyou for your effort
Chad Greene
Chad Greene on 5 Apr 2019
Or this, which is shorter, simpler, and just as effective :-)
title sin(delta)

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!

Translated by