Deletion of handle object

When the object that a handle refers to is deleted, the handle can still exist but, it will not point to anything. In a way, it will become a null handle.  In the following example, we create a handle for an axes object and then display the properties of the handle after deleting the object, to verify whether the handle exists or not.

Example 3:

Matlab




% Code
ax = axes;
x=0:.3:3;
plot(ax,x,x)


Output:

 

As we can see, ax points to our axes object. Now, we shall delete the handle. And as explained above, it will delete the object that the handle refers to instead of the handle itself.

Example 4: 

Matlab




% Code
ax = axes;
x=0:.3:3;
plot(ax,x,x)
delete(ax)
%checking whether the handle still exists or not
whos("ax")


Output:

 

As can be seen, the handle still exists however, the object it refers to is deleted.

Handle Object Behavior in MATLAB

Handles in MATLAB are data type that points to an object. The handles can be used to point to an object from different references or to pass a function to another function as an input argument.

We shall not explain the creation and usage of MATLAB handles, as they are out of this article’s scope. However, MATLAB handles have some special properties that we shall discuss in this article.

Similar Reads

Copies of a MATLAB handle

When a copy of a handle object is created, it still points to the same object as the original handle. See the following example to understand it better....

Modification of handles using functions

...

Deletion of handle object

MATLAB allows to modification of the handles as arguments to functions, which directly accesses the object referred to by the function....

Checking whether an object is a handle or not

...