Main Content

partialDataRepresentation

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

Build compact display representation from portion of data in object array

Since R2021b

Description

rep = partialDataRepresentation(obj,displayConfiguration,str) builds the compact display representation of the object array obj using the string array str. To construct a representation suitable for display within the container, the method uses the current display context as described in displayConfiguration. The method concatenates the elements of str, followed by the ellipsis symbol specified by displayConfiguration, into a padded display text.

Use this syntax to create a plain-text representation of your object array using its leading elements, leaving out elements from the end of the array.

example

rep = partialDataRepresentation(obj,displayConfiguration,str1,str2) builds a compact display representation of obj using the string arrays str1 and str2. The method concatenates the two string arrays by placing the ellipsis symbol between them.

Use this syntax to create a plain-text representation of your object array using its leading and trailing elements, leaving out the elements in between.

example

rep = partialDataRepresentation(___,Annotation=annotation) also includes the specified annotation in the representation of obj. You can use any of the input argument combinations in the previous syntaxes.

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.

Text representing a subset of the object array, specified as a string array. The number of rows in str must be the same as the number of rows in obj.

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 using its first and last elements separated by an ellipsis symbol.

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 partialDataRepresentation utility method within the compactRepresentationForSingleLine and compactRepresentationForColumn methods, respectively. When array elements are displayed using a single-line layout, add an annotation to describe them.

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

    methods
        function rep = compactRepresentationForSingleLine(obj,displayConfiguration,~)
            str = string(obj);
            rep = partialDataRepresentation(obj,displayConfiguration,str(1),str(end), ...
                Annotation="Free Lunch Days");
        end
        function rep = compactRepresentationForColumn(obj,displayConfiguration,~)
            str = string(obj);
            rep = partialDataRepresentation(obj,displayConfiguration,str(:,1),str(:,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 the first and last elements, separated by an ellipsis symbol, as well as the specified annotation.

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

  struct with fields:

    f: [Monday    …    Friday]  (Free Lunch Days)

Create another Weekdays array with many elements, so that they cannot all be displayed in a single line. As in the previous step, when you assign this array to s.f, MATLAB displays the array using its first and last elements.

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

  struct with fields:

    f: [Friday    …    Friday]  (Free Lunch Days)

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. MATLAB displays the array using its first and last columns, separated by a column of ellipsis symbols.

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

  2×2 table

     Location           FreeLunchDays       
    __________    __________________________

    "Boston"      Monday     …    Wednesday
    "New York"    Tuesday    …    Thursday 

Update the FreeLunchDays variable using a WeekDays array with many elements. As in the previous step, MATLAB displays the array using its first and last columns, separated by a column of ellipsis symbols.

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

  2×2 table

     Location         FreeLunchDays     
    __________    ______________________

    "Boston"      Friday    …    Friday
    "New York"    Friday    …    Friday

Tips

Version History

Introduced in R2021b