MATLAB Programming Fundamentals - MathWorks

(やまだぃちぅ) #1
All methods, except static methods, require the System object handle as the first
input argument. The default value, inserted by MATLAB Editor, is obj. You can use
any name for your System object handle.

By default, the number of inputs and outputs are both one. Inputs and outputs can be
added using Inputs/Outputs. You can also use a variable number of inputs or
outputs, see “Change the Number of Inputs” on page 34-18.

Alternatively, if you create your System object by editing a MAT-file, you can add the
stepImpl method using Insert Method > Implement algorithm.

(^2) Change the computation in the stepImpl method to add 1 to the value of u.
methods (Access = protected)
function y = stepImpl(~,u)
y = u + 1;
end
TipInstead of passing in the object handle, you can use the tilde (~) to indicate that
the object handle is not used in the function. Using the tilde instead of an object
handle prevents warnings about unused variables.
(^3) Remove unused methods that are included by default in the basic template.
You can modify these methods to add more System object actions and properties. You
can also make no changes, and the System object still operates as intended.
The class definition file now has all the code necessary for this System object.
classdef AddOne < matlab.System
% ADDONE Compute an output value one greater than the input value
% All methods occur inside a methods declaration.
% The stepImpl method has protected access
methods (Access = protected)
function y = stepImpl(~,u)
y = u + 1;
end
end
end
34 System object Usage and Authoring

Free download pdf