MATLAB Object-Oriented Programming

(Joyce) #1
The fcnview object stores a handle to the event.listener object in its
HLUpdateGraph property, which is used to enable/disable the listener by a context menu
(see “Enable and Disable Listeners” on page 11-63).

The fcnview object (obj) is added to the two default arguments (src, evnt) passed to
the listener callback. Keep in mind, the source of the event (src) is the fcneval object,
but the fcnview object contains the handle of the surface object that the callback
updates.

The listenUpdateGraph function is defined as follows:

function listenUpdateGraph(obj,src,evnt)
if ishandle(obj.HSurface) % If surface exists
obj.updateSurfaceData % Update surface data
end
end

The updateSurfaceData function is a class method that updates the surface data when
a different mathematical function is assigned to the fcneval object. Updating a graphics
object data is more efficient than creating a new object using the new data:

function updateSurfaceData(obj)
% Get data from fcneval object and set surface data
set(obj.HSurface,...
'XData',obj.FcnObject.Data.X,...
'YData',obj.FcnObject.Data.Y,...
'ZData',obj.FcnObject.Data.Matrix);
end

The PostSet Event Listener


All properties support the predefined PostSet event (See “Property-Set and Query
Events” on page 11-17 for more information on property events). This example uses the
PostSet event for the fcneval Lm property. This property contains a two-element vector
specifying the range over which the mathematical function is evaluated. Just after this
property is changed (by a statement like obj.Lm = [-3 5];), the fcnview objects
listening for this event update the graph to reflect the new data.

11 Events — Sending and Responding to Messages

Free download pdf