Main Content

getHeader

Class: matlab.mixin.CustomDisplay
Namespace: matlab.mixin

Build customized display header text

Syntax

s = getHeader(obj)

Description

s = getHeader(obj) returns the text s used as the header when displaying the object array obj. This method is called once for the entire object array.

Override this method to create a custom header. The overriding implementation must support all states of the object, including scalar, nonscalar, empty, and deleted (if obj is an instance of a handle class).

Input Arguments

expand all

Object array to apply custom header to. The class of obj must be derived from matlab.mixin.CustomDisplay.

Output Arguments

expand all

Custom header text, returned as a char array. Depending on the input obj, the default implementation returns:

  • Scalar — The non-namespace-qualified class name

  • Nonscalar — The non-namespace-qualified class name and dimensions

  • Empty — Empty char

  • Deleted handle — The text "deleted classname handle"

The class name is linked to MATLAB® documentation for the class. Selecting the link displays the helpPopup window.

If you override this method, you might need to terminate s with a newline (\n) character.

Attributes

Accessprotected

To learn about attributes of methods, see Method Attributes.

Examples

expand all

The Tester class has one property, ObjectUnderTest, which can take any type of value. Add a getHeader method that, for scalar instances, identifies the class of the property value and then appends the name of that class to the header.

classdef Tester < matlab.mixin.CustomDisplay
    properties
        ObjectUnderTest
    end
    methods(Access = protected)
        function out = getHeader(obj)
            if ~isscalar(obj)
                out  = getHeader@matlab.mixin.CustomDisplay(obj);
            else
                testerClass = matlab.mixin.CustomDisplay.getClassNameForHeader(obj);
                objectUnderTestClass = class(obj.ObjectUnderTest);
                headerStr = [testerClass ' for ' objectUnderTestClass];
                out =  sprintf('%s\n',headerStr);
            end
        end
    end
end

Create a scalar instance to see the customized header text.

b = Tester;
b.ObjectUnderTest = int8(5)
b = 

Tester for int8

    ObjectUnderTest: 5

Version History

Introduced in R2013b