Prev: Loading a large dataset from a database-- java.lang.OutOfMemoryError: Java heap space
Next: roc in matlab
From: Barry Ridge on 3 Jun 2010 09:34 "Guillaume Perrault Archambault" <guigui.the.bulldozer(a)gmail.com> wrote in message <h5f1pe$2ll$1(a)fred.mathworks.com>... > I need to make a deep copy of a hande object. Is there any easy way to do this in R2009a? I came up with a bit of a hack for doing this. It uses file-handling, and therefore is not so elegant, but it seems to work. Just add this method to whatever class you want to copy: function new = copy(this) save('temp.mat', 'this'); Foo = load('temp.mat'); new = Foo.this; delete('temp.mat'); end Example usage (assumes copy() is a method in class MyClass): A = MyClass(); B = A.copy();
From: Steven Lord on 3 Jun 2010 22:03
"Barry Ridge" <nobody.home(a)sogetthis.com> wrote in message news:hu8b0c$b9e$1(a)fred.mathworks.com... > "Guillaume Perrault Archambault" <guigui.the.bulldozer(a)gmail.com> wrote in > message <h5f1pe$2ll$1(a)fred.mathworks.com>... >> I need to make a deep copy of a hande object. Is there any easy way to do >> this in R2009a? > > I came up with a bit of a hack for doing this. It uses file-handling, and > therefore is not so elegant, but it seems to work. Just add this method to > whatever class you want to copy: > > function new = copy(this) > save('temp.mat', 'this'); > Foo = load('temp.mat'); > new = Foo.this; > delete('temp.mat'); > end > > Example usage (assumes copy() is a method in class MyClass): > A = MyClass(); > B = A.copy(); If modifying the class is an option, then have your clone method in your class instantiate a new empty handle object and set the appropriate properties. Remember, inside a class method, you have access to all the properties of the object. If you don't want to hard-code the list of properties, you could always make use of the meta.class object for your object along with dynamic "field" names (or your class's GET and SET methods, or whatever other property access system you've devised.) http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_oop/br4iuh2.html -- Steve Lord slord(a)mathworks.com comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ To contact Technical Support use the Contact Us link on http://www.mathworks.com |