how to change the position of a suptitle() text in matlab

You can change the position of the suptitle() by setting the Position property of the title object. The Position property is a four-element vector in the form of [left bottom width height]. Here's an example:

main.m
% Create a plot
figure
plot([1 2 3], [4 5 6])

% Add a suptitle
suptitle('My Super Title')

% Get the title object
titleHandle = get(gcf,'NumberTitle', 'off');
titleHandle = get(titleHandle,'Name');
titleHandle = get(titleHandle, 'children');
titleHandle = titleHandle(1); % First title is the suptitle

% Change the position
set(titleHandle, 'Position', [0.5 1.05 0.5])
371 chars
16 lines

In this example, the Position property is set to [0.5 1.05 0.5]. The 0.5 values for left and width center the title horizontally, and the 1.05 value for bottom moves the title slightly above the top of the plot.

related categories

gistlibby LogSnag