MATLAB Programming Fundamentals - MathWorks

(やまだぃちぅ) #1

Create a Whiteboard System object


This example shows the class definition of a Whiteboard System object and how to use
the object. Each time you run the whiteboard object, it draws a line on a whiteboard.


Definition of the Whiteboard System object


type('Whiteboard.m');


classdef Whiteboard < matlab.System
% Whiteboard Draw lines on a figure window
%


properties(Nontunable)
Color (1, 1) ColorValues = ColorValues.blue
end


methods (Access = protected)
function stepImpl(obj)
h = Whiteboard.getWhiteboard();
plot(h, ...
randn([2,1]), randn([2,1]), ...
'Color',char(obj.Color));
end


function releaseImpl(obj)
cla(Whiteboard.getWhiteboard());
hold on
end
end


methods (Static)
function a = getWhiteboard()
h = findobj('tag','whiteboard');
if isempty(h)
h = figure('tag','whiteboard');
hold on
end
a = gca;
end
end
end


Construct the System object.


Limit Property Values to Finite List
Free download pdf