clone
Creates an independent copy of a System object.
Category: Programming > Classes
Syntax
c = clone(obj)
Returns a new object of the same class with the same property values and internal state.
Description
System objects are handle objects, so plain assignment b = a makes b another name for the same object. clone is the way to get a true copy, including any state the object has accumulated, such as the buffer of a filter or the position in a stream. It also copies the locked status of the object.
The example shows the aliasing problem that clone solves, using a handle object that is available everywhere.
Input arguments
obj- A System object (an instance of a class derived from
matlab.System).
Output arguments
c- A separate object. Changes to
cdo not affectobj, and the reverse.
Example
Assignment copies the handle, not the object
a = containers.Map();
b = a;
b('key') = 1;
fprintf('a has %d key, a == b is %d\n', a.Count, a == b)
Output
a has 1 key, a == b is 1
Notes
System objects are not available in MatLivre, so clone cannot be called. The example shows how handle objects behave, which is why a clone is needed.