Main Content

fullDataRepresentation

Class: matlab.mixin.CustomCompactDisplayProvider
Namespace: matlab.mixin

Build compact display representation from all data in object array

Since R2021b

Description

rep = fullDataRepresentation(obj,displayConfiguration) builds the compact display representation of the object array obj using the string converter method defined by the class of obj. The method concatenates all the strings, corresponding to the elements of obj, into a padded display text. To construct a representation suitable for display within the container, the method uses the current display context as described in displayConfiguration.

rep = fullDataRepresentation(obj,displayConfiguration,Name=Value) builds a compact display representation using additional options specified by one or more name-value arguments.

example

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.

Name-Value 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: rep = fullDataRepresentation(obj,displayConfiguration,Annotation="My Object") builds a compact display representation of obj that includes the specified annotation.

Textual representation of the data in the object array, specified as a string array with the same number of rows as obj. When you specify this argument, the method uses the specified string array instead of calling the string converter method of the class on the object array.

Use this argument when the class of the object array does not implement a string converter method or when the converter method does not create a string array suitable for use in a compact display scenario.

Descriptive comment about the object array, specified as an N-by-1 string array, where N is the number of rows in obj. The method appends the specified annotation to the text representing the data in the object array.

Output Arguments

expand all

Compact display representation of the object array, returned as a matlab.display.PlainTextRepresentation or matlab.display.DimensionsAndClassNameRepresentation object.

By default, the method tries to represent obj as a PlainTextRepresentation object. It returns a DimensionsAndClassNameRepresentation object only in these situations:

  • obj is an empty value.

  • obj must use the single-line display layout, but it is not a row vector.

  • obj must use the columnar display layout, but it is not a matrix.

Examples

expand all

Customize the compact display of your object array by fitting all array elements within the available character width, if possible, and also specifying an annotation that depends on the contents of the array.

In your current folder, create the Weekdays enumeration class by subclassing matlab.mixin.CustomCompactDisplayProvider. To customize the compact display for single-line and columnar layouts, place a call to the fullDataRepresentation utility method within the compactRepresentationForSingleLine and compactRepresentationForColumn methods, respectively. Specify the Annotation name-value argument so that MATLAB® displays an annotation for each row of the object array that includes weekend days.

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

    methods
        function rep = compactRepresentationForSingleLine(obj,displayConfiguration,~)
            rep = fullDataRepresentation(obj,displayConfiguration,Annotation=annotation(obj));
        end
        function rep = compactRepresentationForColumn(obj,displayConfiguration,~)
            rep = fullDataRepresentation(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 structure with a field that contains an array of a few Weekdays objects. MATLAB displays all the array elements. Additionally, because the array includes the enumeration member WeekDays.Saturday, MATLAB displays an annotation.

s = struct("FreeLunchDays",[WeekDays.Monday WeekDays.Wednesday WeekDays.Friday WeekDays.Saturday])
s = 

  struct with fields:

    FreeLunchDays: [Monday    Wednesday    Friday    Saturday]  (Includes Weekends)

Create another Weekdays array with many elements, so that they cannot all be displayed in a single line. When you assign this array to s.FreeLunchDays, MATLAB uses the array dimensions and class name.

days = repmat(WeekDays.Friday,1,52); 
s.FreeLunchDays = days
s = 

  struct with fields:

    FreeLunchDays: [1×52 WeekDays]

Now, test the custom compact display of WeekDays objects for columnar layout. Create a table T that contains a WeekDays array comprising a few elements. Because the available character width is large enough, MATLAB displays all the array elements in the Command Window. 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.Wednesday WeekDays.Friday; WeekDays.Thursday WeekDays.Saturday];
T = table(Location,FreeLunchDays)
T =

  2×2 table

     Location                   FreeLunchDays               
    __________    __________________________________________

    "Boston"      Wednesday    Friday                       
    "New York"    Thursday     Saturday  (Includes Weekends)

Update the FreeLunchDays variable using a WeekDays array with many elements. Because MATLAB can no longer display all the array elements within the available character width, it uses the array dimensions and class name.

T.FreeLunchDays = repmat(WeekDays.Friday,2,52)
T =

  2×2 table

     Location     FreeLunchDays
    __________    _____________

    "Boston"      1×52 WeekDays
    "New York"    1×52 WeekDays

Tips

Version History

Introduced in R2021b