Main Content

matlab.diagram.ClassViewer class

Package: matlab.diagram

Create class diagrams in Class Diagram Viewer tool

Description

The matlab.diagram.ClassViewer class provides command line access to the Class Diagram Viewer tool. You can use the properties and methods of this class to populate a class diagram without using the graphical tool.

The matlab.diagram.ClassViewer class is a handle class.

Class Attributes

Sealed
true

For information on class attributes, see Class Attributes.

Creation

Description

matlab.diagram.ClassViewer opens a Class Diagram Viewer instance with no classes loaded.

matlab.diagram.ClassViewer(Name,Value) adds the classes specified to both the Class Browser pane and the canvas. Use Name,Value arguments to determine what content to add.

example

viewer = matlab.diagram.ClassViewer(___) returns a handle for the Class Viewer instance. You can use any of the previous input syntaxes.

Input Arguments

expand all

Name-Value Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside quotes. You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

Example: matlab.diagram.ClassViewer('Classes','matlab.net.http.RequestMessage')

Classes to add to the Class Browser and viewer, specified as a character vector, string, or a vector of strings. You can also use class instances.

Example: matlab.diagram.ClassViewer('Classes','matlab.net.http.ResponseMessage')

Example: respMsg = matlab.net.http.RequestMessage; matlab.diagram.ClassViewer('Classes',respMsg)

Class folders to add to the Class Browser and viewer, specified as a character vector, string, or a vector of strings.

Determines whether to include classes from subfolders, specified as a numeric or logical 1 (true) or 0 (false). A value of 1 includes classes in subfolders of the Folders argument, and 0 omits them.

Packages to add to the Class Browser and viewer, specified as a character vector, string, or a vector of strings.

Determines whether to include classes from subpackages, specified as a numeric or logical 1 (true) or 0 (false). A value of 1 includes the classes in subpackages of the Packages argument, and 0 omits them.

Path of class diagram to load, specified as a character vector, string, or a vector of strings.

Determines whether the Class Viewer window is visible after creation, specified as a numeric or logical 0 (false) or 1 (true). A value of 1 makes the window visible, and 0 hides it.

Properties

expand all

The last file loaded or saved to the Class Viewer instance, specified as a string. This property can only be set by the load and save methods.

Attributes:

Dependent
true

The list of classes currently displayed in the diagram, specified as a string array. The list includes classes displayed in the canvas, but it does not include classes that are only listed in the Class Browser.

Attributes:

Dependent
true

Determines whether the Class Viewer displays mixin classes, specified as a numeric or logical 0 (false) or 1 (true). A value of 0 excludes mixins and the handle class for a simpler diagram. A value of 1 enables adding mixins when adding superclasses, but it does not do so automatically.

Determines whether the Class Viewer displays the package names on the class cards, specified as a numeric or logical 1 (true) or 0 (false). A value of 1 displays the package names, and 0 hides them.

Determines whether the Class Viewer window is currently displayed, specified as a numeric or logical 0 (false) or 1 (true). A value of 1 makes the window visible, and 0 hides it.

Attributes:

Transient
true

Methods

expand all

Examples

collapse all

Construct a Class Viewer instance with one class preloaded. The class appears in both the Class Browser and the canvas.

httpViewer = matlab.diagram.ClassViewer('Classes','matlab.net.http.RequestMessage')

Class Viewer showing RequestMessage

Use the addClass method to add two additional classes to the diagram. Because matlab.net.http.Message is the superclass of the other two classes, the Class Viewer automatically connects them.

addClass(httpViewer,["matlab.net.http.Message",...
"matlab.net.http.ResponseMessage"])

Class Viewer showing three classes

Expand the class card for ResponseMessage.

expandClass(httpViewer,"matlab.net.http.ResponseMessage",1)

Class Viewer showing three classes, ResponseMessage expanded

Collapse the Properties section on the class card for ResponseMessage.

expandSection(httpViewer,"matlab.net.http.ResponseMessage","Properties",0)

Class Viewer showing three classes, ResponseMessage properties collapsed

Save the diagram as an MLDATX file.

save(httpViewer,"filepath/httpMessages.mldatx")
Introduced in R2021a