Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copy MATLAB object of a handle class

Tags:

matlab

I've implemented a handle class in MATLAB, and I've tried to copy an object of the class by calling the following two functions:

objByteArray = getByteStreamFromArray(obj);
newObj = getArrayFromByteStream(objByteArray);

But from time to time I get the following error:

Error using getArrayFromByteStream Unable to read data stream because the data contains a bad version or endian-key

Is there another way to copy an object of a handle class?

like image 533
Mario Avatar asked Dec 31 '25 17:12

Mario


1 Answers

Since you're working with a handle class, you can inherit your class from matlab.mixin.Copyable, which will give your class a customizable copy method.

By default, the copy method will implement a shallow copy of the class properties (i.e. if the class properties are themselves handle classes, the copies will be references to the original properties), but you can customize the copy operation to implement a deep copy (i.e. a copy operation is performed on the class properties as well).

Documentation for matlab.mixin.Copyable.

like image 159
Sam Roberts Avatar answered Jan 05 '26 05:01

Sam Roberts



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!