MATLAB Examples

Create a Whiteboard System object

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

Contents

Display System object used in this example

type('Whiteboard.m');
classdef Whiteboard < matlab.System
    % Whiteboard Draw lines on a figure window
    %
    properties
        Color = 'blue'
    end
    
    properties (Hidden)
        % Choose a color
        ColorSet = matlab.system.StringSet({'red','blue','green'});
    end
    
    methods (Access = protected)
        function stepImpl(obj)
            h = Whiteboard.getWhiteboard();
            plot(h, ...
                randn([2,1]), randn([2,1]), ...
                'Color',obj.Color(1));
        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

hGreenInk = Whiteboard;
hBlueInk  = Whiteboard;

Change the color

hGreenInk.Color = 'green';
hBlueInk.Color = 'blue';

Draw a few lines

for i=1:3
  hGreenInk();
  hBlueInk();
end

Clear the whiteboard

hBlueInk.release();