Main Content

matlab.display.DimensionsAndClassNameRepresentation class

Package: matlab.display
Superclasses: matlab.display.CompactDisplayRepresentation

Compact display representation using dimensions and class name

Description

The matlab.display.DimensionsAndClassNameRepresentation class provides a compact display representation of an object array using its dimensions and class name.

Class Attributes

Sealed
true

For information on class attributes, see Class Attributes.

Creation

Description

rep = matlab.display.DimensionsAndClassNameRepresentation(obj,displayConfiguration) uses the current compact display configuration to construct a DimensionsAndClassNameRepresentation object.

example

rep = matlab.display.DimensionsAndClassNameRepresentation(obj,displayConfiguration,Name=Value) sets properties using name-value arguments. You can set the UseSimpleName property, the Annotation property, or both. For example, rep = matlab.display.DimensionsAndClassNameRepresentation(obj,displayConfiguration,UseSimpleName=false,Annotation="My Object") constructs a representation that uses the fully qualified class name and the specified annotation.

Input Arguments

expand all

Object array to display, specified as an object array of a class derived from matlab.mixin.CustomCompactDisplayProvider.

Description of the current display context, specified as a matlab.display.DisplayConfiguration object.

Properties

expand all

Whether to use the simple class name, specified as true or false.

By default, the representation uses the simple class name. If the property is set to false, then the representation uses the fully qualified class name.

Attributes:

GetAccess
public
SetAccess
immutable

Descriptive comment about the object array shown as part of its compact display representation, specified as an N-by-1 string array. The shape of Annotation depends on the display layout:

  • Single-line layout — A string scalar

  • Columnar layout — An N-by-1 array of string scalars, where N is the number of rows in the object array

Attributes:

GetAccess
public
SetAccess
immutable

Finalized padded display text, specified as an N-by-1 string array. The shape of PaddedDisplayOutput depends on the display layout:

  • Single-line layout — A padded string scalar

  • Columnar layout — An N-by-1 array of padded string scalars, where N is the number of rows in the object array

Attributes:

GetAccess
public
SetAccess
immutable

Character width of the finalized padded display text, specified as a numeric array. The shape of CharacterWidth depends on the display layout:

  • Single-line layout — A numeric scalar

  • Columnar layout — An N-by-1 array of numeric scalars, where N is the number of rows in the object array

Attributes:

GetAccess
public
SetAccess
immutable

Examples

collapse all

Customize the way your object array is displayed in a table by specifying an annotation that depends on the contents of the array.

In your current folder, create the Weekdays enumeration class by subclassing the matlab.mixin.CustomCompactDisplayProvider interface. Customize the compact display for columnar layout so that MATLAB® displays an annotation for each row of the object array that includes weekend days. To customize the compact display, override the compactRepresentationForColumn method to return a DimensionsAndClassNameRepresentation object with the desired annotation.

classdef WeekDays < matlab.mixin.CustomCompactDisplayProvider
    enumeration
        Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday
    end

    methods
        function rep = compactRepresentationForColumn(obj,displayConfiguration,~)
            import matlab.display.DimensionsAndClassNameRepresentation
            % Represent the array using its dimensions, class name, and annotation
            rep = DimensionsAndClassNameRepresentation(obj,displayConfiguration, ...
                Annotation=annotation(obj));
        end
        function res = annotation(obj)
            % Construct annotation as a column vector of strings
            numRows = size(obj,1);
            res = strings(numRows,1);
            for i = 1:numRows   % Add text for each row that includes weekend days
                currentRow = obj(i,:);
                if any(currentRow == WeekDays.Saturday) || any(currentRow == WeekDays.Sunday)
                    res(i) = "Includes Weekends";
                end
            end
        end
    end
end

In the Command Window, create a table T that contains a 2-by-3 WeekDays array. MATLAB displays the array using its dimensions and class name. Additionally, because the second row of the array includes the enumeration member WeekDays.Saturday, MATLAB displays an annotation for that row.

Location = ["Boston"; "New York"];
FreeLunchDays = [WeekDays.Monday WeekDays.Wednesday WeekDays.Friday; ...
    WeekDays.Tuesday WeekDays.Thursday WeekDays.Saturday];
T = table(Location,FreeLunchDays)
T =

  2×2 table

     Location               FreeLunchDays          
    __________    _________________________________

    "Boston"      1×3 WeekDays                     
    "New York"    1×3 WeekDays  (Includes Weekends)
Introduced in R2021b