How to create different handle objects in Matlab? Matlab OOP 13 | applied electronics engineering

Latest

How to create different handle objects in Matlab? Matlab OOP 13

By Applied Electronics - Saturday, February 11, 2017 No Comments
In this Matlab Object Oriented Programming tutorial we show how to create different handle objects in Matlab. This is 13th part of Object Oriented Programming with Matlab.

In previous tutorial User Defined Handle Class, we said that making a copy of one handle object creates another handle object with same properties and methods. That is both the objects will be referenced in same memory location.

This brings up the questions whether it means that no two handle objects will be different. This is not the case and this is what will be explained here. You can create different handle objects but not by copying another handle object but by instantiating a new handle object.

Say that you created handle object h1. If you create a handle object h2 by copying h1 then h1 and h2 will the same because they reference to same memory location.

>> h1 = rect;
>> h2 = h1;
>> h2 == h1
1

h1 and h2 are same, where rect is a handle class.

To create another and different handle object h3 you have to instantiate a new object as in the following example.

>> h3 =  rect;
>> h3 == h1
0

The same thing in matlab program is shown below.

>> h1 = rect;
>> h2 = h1;
>> h2 == h1

ans =

     1

>> h3 = rect;
>> h3 == h1

ans =

     0

This illustrates the very difference between value class and handle class. See Value classes Vs Handle classes - Matlab OOP 11.

 

No Comment to " How to create different handle objects in Matlab? Matlab OOP 13 "