MATLAB Object-Oriented Programming

(Joyce) #1

@fcneval/fcneval.m Class Code


classdef fcneval < handle
properties
FofXY
end
properties (SetObservable = true)
Lm = [-2*pi 2*pi]
end % properties SetObservable = true
properties (Dependent = true)
Data
end
events
UpdateGraph
end
methods
function obj = fcneval(fcn_handle,limits) % Constructor returns object
if nargin > 0
obj.FofXY = fcn_handle; % Assign property values
obj.Lm = limits;
end
end
function set.FofXY(obj,func)
me = fcneval.isSuitable(func);
if ~isempty(me)
throw(me)
end
obj.FofXY = func;
notify(obj,'UpdateGraph');
end
function set.Lm(obj,lim)
if ~(lim(1) < lim(2))
error('Limits must be monotonically increasing')
else
obj.Lm = lim;
end
end
function data = get.Data(obj)
[x,y] = fcneval.grid(obj.Lm);
matrix = obj.FofXY(x,y);
data.X = x;
data.Y = y;
data.Matrix = real(matrix);
end
end % methods

11 Events — Sending and Responding to Messages

Free download pdf