The OnOffSwitchState
class enables you to form text expressions by
concatenating enumeration members with character vectors or strings. For example, if
an object property named Power
contains an enumeration member of
the OnOffSwitchState
class, you can form a character array with a
character vector and the property value:
a = SystemState;
a.Power = true;
['The power switch is currently ' a.Power]
ans =
'The power switch is currently on'
Normally, when forming an array by concatenating character vectors or strings with
enumeration members, MATLAB® attempts to convert the text to the class of the enumeration member.
However, the OnOffSwitchState
class defines specialized behavior that
enables concatenation of enumeration members and text in cases where the text does
not correspond to enumeration members defined by the class. In these cases,
MATLAB creates an array of the same type as the text.
Here are the rules that MATLAB applies when concatenating character vectors or strings with
enumeration members of the OnOffSwitchState
class.
If all array elements are either OnOffSwitchState
enumeration members or character vectors, all enumeration members are
converted to their char
equivalent representation. The
resulting array is of type char
.
If all array elements are either OnOffSwitchState
enumeration members or strings, all enumeration members are converted to
their string
equivalent representation. The resulting array
is of type string
.
If all array elements are either OnOffSwitchState
enumeration members, strings, or character vectors, all enumeration members
and character vectors are converted to their string
equivalent representation. The resulting array is of type string
.
In all other cases, normal concatenation rules apply. For more
information, see Concatenating Objects of Different Classes.