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.

Example 1:

Matlab




% Code
fh = @fun;
fprintf('First handle: ')
disp(fh(3))
  
%creating copy of the handle fh
h=fh;
fprintf('Copied handle: ')
disp(h(2))
  
%function
function result = fun(x)
result = x^3;
end


Output:

 

As can be seen here, the copied handle and its original handle, both point to the same object, the function fun

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

...