Syntax
SGtitle([n,w])
Input Parameter
n : | | hierarchy of calling functions; default is 0; |
w : | | 'window' renames the window instead of a gca title |
Examples
SGfigure; SGtitle
SGfigure; SGtitle(1)
SGfigure; SGtitle(-1)
Copyright 2017-2025 Tim C. Lueth. All rights reserved. The code is the property of Tim C. Lueth and may not be redistributed or modified without explicit written permission. This software may be used free of charge for academic research and teaching purposes only. Commercial use, redistribution, modification, or reverse engineering is strictly prohibited. Access to source code is restricted and granted only under specific agreements. For licensing inquiries or commercial use, please contact: Tim C. Lueth
Algorithm (Workflow)
This function, SGtitle
, is designed to set the title of a figure or window in MATLAB. It is part of the SolidGeometry library and was created to address a conflict with MATLAB's built-in sgtitle
function introduced in version 2018b.
Input Parameters
- n: This parameter specifies the hierarchy level of the calling functions. The default value is 0. It determines which function name in the call stack is used as the title.
- w: This parameter determines whether the title is applied to the window or the current axes. If set to 'window', it renames the window instead of setting a title for the current axes.
Algorithm Steps
- Initialize
n
to 0 and w
to an empty string. These are default values.
- Check if there are input arguments. If the first argument is provided and not empty, set
n
to this value. If the second argument is provided and not empty, set w
to this value.
- If there is more than one axes object in the current figure, set
w
to 'fig'. This ensures that the title is applied to the figure rather than individual subplots.
- Retrieve the title string using the
titleofcaller
function, which uses the hierarchy level n
to determine the appropriate function name from the call stack.
- Use a switch statement to determine how to apply the title based on the value of
w
:
- Case 'win', 'window', 'windows': Set the name of the current figure window to the title string
t
.
- Case 'fig', 'figure', 'subplots': Use the
sgtitle
function to set the title for the entire figure, ensuring that underscores are not interpreted as subscripts by setting the 'Interpreter' to 'none'.
- Default case: Set the title of the current axes using the
title
function, again ensuring that underscores are not interpreted as subscripts.
Algorithm explaination created using ChatGPT on 2025-08-19 01:38. (Please note: No guarantee for the correctness of this explanation)
Last html export of this page out of FM database by TL: 2025-09-21