matlab.mixin.Heterogeneous.getDefaultScalarElement
Class: matlab.mixin.Heterogeneous
Namespace: matlab.mixin
Return default object for heterogeneous array operations
Syntax
defaultObject = getDefaultScalarElement
Description
returns
the default object for a heterogeneous hierarchy. The implementation of
defaultObject = getDefaultScalarElementgetDefaultScalarElement inherited from the
matlab.mixin.Heterogeneous class returns an instance of the
root class. The root class is the direct subclass of
matlab.mixin.Heterogeneous in a heterogeneous hierarchy.
If the root class is abstract or is not an appropriate default object for the classes in
the heterogeneous hierarchy, you must override getDefaultScalarElement in
the root class to return a default object. getDefaultScalarElement must
return a scalar instance of another member of the heterogeneous hierarchy.
MATLAB® calls the getDefaultScalarElement method to fill in gaps in a
heterogeneous array. For more information, see Defining the Default Object.
Output Arguments
Examples
This example describes a heterogeneous hierarchy with a root class
(FinancialObjects) that is an abstract class and therefore cannot be
used for the default object.

The FinancialObjects class definition includes an override of the
getDefaultScalarElement method, which returns an instance of the
Assets class as the default object.
classdef FinancialObjects < matlab.mixin.Heterogeneous methods (Abstract) val = determineCurrentValue(obj) end methods (Static,Sealed,Access=protected) function default_object = getDefaultScalarElement default_object = Assets; end end end
Tips
Override
getDefaultScalarElementonly if the root class is not suitable as a default object.Override
getDefaultScalarElementonly in the root class of the heterogeneous hierarchy.getDefaultScalarElementmust return a scalar object.getDefaultScalarElementmust be a static method with protected access. While not required by MATLAB, you can seal this method to prevent overriding by other classes.MATLAB returns an error if the value returned by
getDefaultScalarElementis not scalar or is not an instance of a class that is a valid member of the hierarchy.
Version History
Introduced in R2011b