Clone Handle Object - using MATLAB OOP

How to clone an object (deep copy) which inherits reference behaviour from the 'handle' class.


Updated 1 Sep 2016

View License

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.

Cite As

Bobby Nedelkovski (2023). Clone Handle Object - using MATLAB OOP (, MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2009b
Compatible with any release
Platform Compatibility
Windows macOS Linux
Find more on Software Development Tools in Help Center and MATLAB Answers

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!


Version Published Release Notes

Updated license

Added copyright protection to Description field and associated files . Verified this item works with MATLAB R2009b.

This demo has been updated to use Dynamic Expressions when copying properties of an object.