Create and manage class alias definitions
matlab.alias.AliasFileManager class enables you to create and manage
class alias definitions. The alias definitions map a new class name to one or more old names.
Use this functionality to change the name of an existing class while maintaining compatibility
with code and MAT-files that use the older names of the class.
The recommended process for creating aliases is to write a function to create an instance
AliasFileManager. For more information and examples, see Creating and Managing Class Aliases.
matlab.alias.AliasFileManager class is a
For information on class attributes, see Class Attributes.
creates a default
fileMgr = matlab.alias.AliasFileManager
fileMgr = matlab.alias.AliasFileManager(
AliasFileManager instance and loads the
file in the specified
the path to the parent folder of the
resources folder containing an
alias definition file. Using this syntax provides a convenient way to view all of the
defined class aliases at
location — Path to folder containing existing alias file
The path to a folder containing an existing class alias file, specified as a
string scalar. The path must point to the parent folder of the
resources folder containing an alias definition file. If no
alias file exists at that location, MATLAB® errors.
location can be a full or partial path. Full paths are not
recommended for code that is packaged for use by others because installation paths
Aliases — Class alias definitions
Class alias definitions, specified as an array of
objects. The property contains current class name and all active old aliases for all
classes in a given folder.
a new class alias definition to the
alias definitions from
Create Class Alias File
This example shows how to use a function to create a class alias file.
This example renames the class
SecondName. To accomplish this, an alias definition file is created that
SecondName as the new class name and
as an old alias.
The class file with the new name,
SecondName.m, is in a folder named
Work. The function
createAliasFile is also in
createAliasFile function is run from the
Work folder. The function creates
instance of class
adds the new and old names of the class to
fileMgr. Finally, the
writeAlias method writes the alias definition file inside a
resources folder. The method creates the folder if it does not
function createAliasFile fileMgr = matlab.alias.AliasFileManager; addAlias(fileMgr,NewName="SecondName",OldNames="FirstName"); writeAliasFile(fileMgr); end
Change the current working directory to the
Work folder and call
The function creates the
resources folder and the
alias definition file inside of it.
MATLAB now recognizes both class names, and instances constructed using either
name are defined as instances of
old = FirstName new = SecondName
old = SecondName with no properties. new = SecondName with no properties.
The function workflow demonstrated in the example has the advantage of automatically clearing the instance of
Deprecating old class aliases is not recommended. Removing the old aliases risks compatibility issues for the users of your code. To access an existing alias definition file, use the
location) constructor and read its Aliases property.