title
Adds a title to the axes, figure layout or chart.
Category: Graphics > Formatting and Annotation
Syntax
title(txt)
Sets the title of the current axes.
title(txt, Name, Value)
Sets text properties such as 'FontSize', 'Color' or 'FontWeight'.
title(target, ___)
Sets the title of the axes or tiled layout target.
t = title(___)
Returns the text object.
Description
The title is centered above the axes, in a bold font by default. It is stored in the axes property Title, so a later title replaces it. TeX markup (\alpha, x^2) is interpreted unless 'Interpreter' is changed.
To build a title from numbers, create the text first with sprintf or num2str, for example title(sprintf('n = %d', n)).
Input arguments
txt- Title as text, a string array or a cell array of lines (a multi-line title).
Output arguments
t- Text object, class
matlab.graphics.primitive.Text.
Example
A title built from a value
n = 5;
plot(1:n)
t = title(sprintf('Line with n = %d', n), 'FontSize', 14);
t.String
t.FontSize
Output
ans = 'Line with n = 5'
ans = 14