Handle Input Specification Changes - MATLAB & Simulink (original) (raw)
Main Content
This example shows how to control the input specifications for a System objectâ„¢. You can control what happens when an input specification changes.
You can also restrict whether the input complexity, data type, or size can change while the object is in use. Whichever aspects you restrict cannot change until after the user calls release
.
React to Input Specification Changes
To modify the System object algorithm or properties when the input changes size, data type, or complexity, implement the processInputSpecificationChangeImpl method. Specify actions to take when the input specification changes between calls to the System object.
In this example, processInputSpecificationChangeImpl
changes theisComplex
property when either input is complex.
properties(Access = private) isComplex (1,1) logical = false; end
methods (Access = protected) function processInputSpecificationChangeImpl(obj,input1,input2) if(isreal(input1) && isreal(input2)) obj.isComplex = false; else obj.isComplex = true; end end end
Restrict Input Specification Changes
To specify that the input complexity, data type, and size cannot change while the System object is in use, implement the isInputComplexityMutableImpl, isInputDataTypeMutableImpl, and isInputSizeMutableImpl methods to return false
. If you want to restrict only some aspects of the System object input, you can include only one or two of these methods.
methods (Access = protected)
function flag = isInputComplexityMutableImpl(,)
flag = false;
end
function flag = isInputDataTypeMutableImpl(,)
flag = false;
end
function flag = isInputSizeMutableImpl(,)
flag = false;
end
end
Complete Class Definition File
This Counter
System object restricts all three aspects of the input specification.
classdef Counter < matlab.System %Counter Count values above a threshold
properties
Threshold = 1
end
properties (DiscreteState)
Count
end
methods
function obj = Counter(varargin)
setProperties(obj,nargin,varargin{:});
end
end
methods (Access=protected)
function resetImpl(obj)
obj.Count = 0;
end
function y = stepImpl(obj, u1)
if (any(u1 >= obj.Threshold))
obj.Count = obj.Count + 1;
end
y = obj.Count;
end
function flag = isInputComplexityMutableImpl(~,~)
flag = false;
end
function flag = isInputDataTypeMutableImpl(~,~)
flag = false;
end
function flag = isInputSizeMutableImpl(~,~)
flag = false;
end
end
end