Subscripted Assignment
In subscripted assignment, the left side of the assignment statement defines the class of
the array. If you assign array elements when the right side is a different class than the left
side, MATLAB attempts to convert to the class of the left side.
For example, assigning an object of ClassB to an element of array A requires conversion.
A = ClassA;
B = ClassB;
A(2) = B;
MATLAB first looks for a converter method defined by the class of the source object B.
This converter method must have the name ClassA. The subscripted assignment is
effectively a call to the converter defined by ClassB:
A(2) = B.ClassA % Call method of ClassB
If no converter method exists, MATLAB passes the source object to the destination class
constructor:
A(2) = ClassA(B) % Call ClassA constructor
See Also
Related Examples
- “Valid Combinations of Unlike Classes”
- “Concatenating Objects of Different Classes” on page 10-18
- “Object Converters” on page 17-12
See Also