Clone Handle Object - using MATLAB OOP
by Bobby Nedelkovski
12 Feb 2009
(Updated 28 Sep 2009)
How to clone an object (deep copy) which inherits reference behaviour from the 'handle' class.
|
Watch this File
|
| File Information |
| Description |
The motivation for this demo is that if you have an instance (say 'a') of a custom class that subclasses 'handle', then the command 'b = a;' will produce another reference 'b' to the same object as initially referenced by 'a', effectively creating a 'shallow' copy of the object.
The link to this demo contains a test class which contains the code necessary to produce a clone or 'deep' copy of its instance by way of a method and alternatively, through its constructor.
A test script is provided to demonstrate the cloning of instances of the test class.
Written by Sam Oliver & Bobby Nedelkovski
The MathWorks Australia Pty Ltd
Copyright 2009, The MathWorks, Inc. |
| Acknowledgements |
This submission has inspired the following:
Copy / Clone method for handle and hgsetget class
|
| MATLAB release |
MATLAB 7.9 (2009b)
|
|
Tags for This File
|
| Everyone's Tags |
|
| Tags I've Applied |
|
| Add New Tags |
Please login to tag files.
|
| Updates |
| 07 May 2009 |
This demo has been updated to use Dynamic Expressions when copying properties of an object. |
| 28 Sep 2009 |
Added copyright protection to Description field and associated files . Verified this item works with MATLAB R2009b. |
|
Contact us at files@mathworks.com