MATLAB Object-Oriented Programming

(Joyce) #1

Find Objects with Specific Values


In this section...
“Find Handle Objects” on page 16-10
“Find by Attribute Settings” on page 16-11

Find Handle Objects


Use the handle class findobj method to find objects that have properties with specific
values. For example, the following class defines a PhoneBook object to represent a
telephone book entry in a data base. The PhoneBook class subclasses the dynamicprops
class, which derives from handle.

classdef PhoneBook < dynamicprops
properties
Name
Address
Number
end
methods
function obj = PhoneBook(n,a,p)
obj.Name = n;
obj.Address = a;
obj.Number = p;
end
end
end

Here are three of the PhoneBook entries in the database:
PB(1) = PhoneBook('Nancy Vidal','123 Washington Street','5081234567');
PB(2) = PhoneBook('Nancy Vidal','123 Main Street','5081234568');
PB(3) = PhoneBook('Nancy Wong','123 South Street','5081234569');

One of these three PhoneBook objects has a dynamic property:

PB(2).addprop('HighSpeedInternet');
PB(2).HighSpeedInternet = '1M';

Find Property/Value Pairs

Find the object representing employee Nancy Wong and display the name and number by
concatenating the strings:

16 Information from Class Metadata

Free download pdf