matlab.diagram.ClassViewer Class
Namespace: matlab.diagram
Description
The matlab.diagram.ClassViewer
class provides command-line access to the
Class Diagram Viewer app. You can use the
properties and methods of this class to populate a class diagram without using the graphical
interface.
The matlab.diagram.ClassViewer
class is a handle
class.
Creation
Description
matlab.diagram.ClassViewer
opens a Class Diagram Viewer instance
with no classes loaded.
matlab.diagram.ClassViewer(
adds
the specified classes to both the Class Browser pane and the canvas.
Use name-value arguments to determine what content to add.Name,Value
)
viewer = matlab.diagram.ClassViewer(___)
returns a
handle for the Class Diagram Viewer instance. You can use any of the previous input
argument syntaxes.
Input Arguments
Specify optional pairs of arguments as
Name1=Value1,...,NameN=ValueN
, where Name
is
the argument name and Value
is the corresponding value.
Name-value arguments must appear after other arguments, but the order of the
pairs does not matter.
Example: matlab.diagram.ClassViewer(Classes="matlab.net.http.RequestMessage")
Classes
— Classes to add to viewer
character vector | string scalar | vector of strings | class instance
Classes to add to the Class Browser and viewer, specified as a character vector, string scalar, 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)
Folders
— Class folders to add to viewer
character vector | string scalar | vector of strings
Class folders to add to the Class Browser and viewer, specified as a character vector, string scalar, or a vector of strings.
IncludeSubfolders
— Include classes from subfolders
true
or 1
(default) | false
or 0
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.
Namespaces
— Namespaces to add to viewer
character vector | string scalar | vector of strings
Namespaces to add to the Class Browser and canvas, specified as a character vector, string scalar, or a vector of strings.
IncludeInnerNamespaces
— Include classes from inner namespaces
true
or 1
(default) | false
or 0
Determines whether to include classes from inner namespaces, specified as a
numeric or logical 1
(true
) or
0
(false
). A value of 1
includes the classes in inner namespaces of the Namespaces
argument, and 0
omits them.
Load
— Path of class diagram to load
character vector | string | string array
Path of class diagram to load, specified as a character vector, string, or a vector of strings.
Packages
— Packages to add to viewer
character vector | string scalar | vector of strings
Since R2024b
Packages to add to the Class Browser and canvas, specified as a character vector, string scalar, or a vector of strings.
Visible
— Display Class Diagram Viewer instance
true
or 1
(default) | false
or 0
Determines whether the Class Diagram 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
ActiveFile
— Last file loaded or saved
string
The last file loaded or saved to the Class Diagram Viewer instance, returned as a
string. This property can only be set by the load
and
save
methods.
Attributes:
Dependent | true |
ClassesInDiagram
— List of classes currently in diagram
vector of strings
The list of classes currently displayed in the diagram, returned as a vector of strings. 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 |
ShowAssociations
— Display associations
false
or 0
(default) | true
or 1
Since R2024a
Determines whether the Class Diagram Viewer displays associations, specified as a
numeric or logical 0
(false
) or
1
(true
). A value of 0
excludes associations. Toggling between true
and
false
immediately updates the diagram. For more information on
associations, see Add Associations to Diagrams.
ShowMixins
— Display mixin classes
false
or 0
(default) | true
or 1
Determines whether the Class Diagram 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.
ShowNamespace
— Display namespace names
true
or 1
(default) | false
or 0
Determines whether the Class Diagram Viewer displays the namespace names on the
class cards, specified as a numeric or logical 1
(true
) or 0
(false
). A value
of 1
displays the namespace names, and 0
hides
them.
Visible
— Display Class Diagram Viewer instance
true
or 1
(default) | false
or 0
Determines whether the Class Diagram 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
Public Methods
addClass |
Add classes to the Class Browser and canvas. Input Arguments
|
removeClass |
Remove classes from the canvas. Classes are not removed from the Class Browser. Input Arguments
|
removeAllClasses |
Remove all classes from the canvas. Classes are not removed from the Class Browser. Input Arguments
|
importClassesFrom |
Add classes to the Class Browser and canvas. Input Arguments
Name-Value Arguments
|
expandClass |
Expand or collapse all sections of a class card on the canvas. Input Arguments
|
expandAll |
Expand or collapse all sections of the class cards on the canvas. Input Arguments
|
expandSection |
Expand or collapse a specified section of a class card on the canvas. Input Arguments
Expanding one section in a class card that is currently collapsed expands all sections of that card. |
importCurrentProject |
Import classes from the current project.
|
export |
Export a class diagram as an image. Input Arguments
Name-Value Arguments
|
load |
Load a diagram saved as an MLDATX file. The loaded diagram replaces any content currently in the Class Diagram Viewer instance. Input Arguments
|
save |
Save a diagram as an MLDATX file. Input Arguments
|
getVisibleViewers |
Static method Return an array of all current |
Examples
Create and Save Class Diagram
Construct a Class Diagram 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")
Use the addClass
method to add two classes to the diagram. Because
matlab.net.http.Message
is the superclass of the other two classes, the
Class Diagram Viewer automatically connects them.
addClass(httpViewer,["matlab.net.http.Message",... "matlab.net.http.ResponseMessage"])
Expand the class card for ResponseMessage
.
expandClass(httpViewer,"matlab.net.http.ResponseMessage",1)
Collapse the Properties section on the class card for
ResponseMessage
.
expandSection(httpViewer,"matlab.net.http.ResponseMessage","Properties",0)
Save the diagram as an MLDATX file.
save(httpViewer,"filepath/httpMessages.mldatx")
Version History
Introduced in R2021aR2024b: Import MATLAB packages
The Class Diagram Viewer can now import classes from MATLAB® packages. Use the importClassesFrom
method with the
Packages
name-value argument. For more information on packages, see
Organize and Distribute Code Using MATLAB Package Manager.
R2024a: New property for displaying associations
The Class Diagram Viewer can now identify and display associations between classes. Use
the ShowAssociations
property to toggle associations on and off in a
diagram.
R2024a: Packages are now called namespaces
MATLAB now refers to packages as namespaces. Several class members have been renamed to reflect this change. Their behavior remains the same.
Member Name in R2023b and Earlier | New Name as of R2024a |
---|---|
Constructor: Packages name-value argument | Namespaces |
Constructor: IncludeSubpackages name-value argument | IncludeInnerNamespaces |
Property: ShowPackageNames | ShowNamespace |
Method: importClassesFrom , Packages
name-value argument | Namespaces |
Method: importClassesFrom ,
IncludeSubpackages name-value argument | IncludeInnerNamespaces |
See Also
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)