Be the first to rate this file! 8 Downloads (last 30 days) File Size: 4.29 KB File ID: #34762

Copy / Clone method for handle and hgsetget class

by Sebastian Hölz

 

25 Jan 2012

Enable deep copying of child objects of classes handle or hgsetget

| Watch this File

File Information
Description

The handle or hgsetget classes miss a method to make deep copies of objects. The two classes "handleplus" and "hgsetgetplus" take care of this.

To use these classes, ...
- simply put them somewhere on your Matlab path.
- in classdef-files change instances of
  "classdef MyClass < handle" (or hgsetget)
to
  "classdef MyClass < handleplus" (or hgsetgetplus)

Suppose you have defined a "MyClass" as child of "handleplus". Deep copies are now created as follows:
>> OBJ = MyClass;
>> OBJ_new = OBJ.copy;

Some short notes:
- This implementation (hopefully) also handles deep copying of inherited private or protected properties (s. discussion "Clone Handle Object - using MATLAB OOP" -> link in acknowledgments).
- It handles properties, which contain handle-objects
- It does not handle cyclic references (s. mathforum.org/kb/message.jspa?messageID=7629086&tstart=0)

Please read the help for these files for more details and report any bugs.

Cheers

Sebastian

Acknowledgements

The author wishes to acknowledge the following in the creation of this submission:
Clone Handle Object - using MATLAB OOP

Required Products MATLAB
MATLAB release MATLAB 7.13 (2011b)
Other requirements This will only work for Matlab releases, which can handle the new OOP-style. To my knowledge, this was implemented in Matlab 7.6.
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
deep copy clone hgsetget handle class oop Sebastian Hölz 25 Jan 2012 10:27:59
oop per isakson 25 Feb 2012 20:10:29

Contact us at files@mathworks.com