Hide Inactive Properties
To display only active System object™ properties, use the isInactivePropertyImpl method. This method
specifies whether a property is inactive. An inactive property is a
property that does not affect the System object because of the value of other properties. When you pass the
isInactiveProperty method a property and the method returns
true, then that property is inactive and does not display when the
disp function is called.
Specify Inactive Property
This example uses the isInactiveProperty method to check the value of a
dependent property. For this System object, the InitialValue property is not relevant if the
UseRandomInitialValue property is set to true. This
isInactiveProperty method checks for that situation and if
UseRandomInitialValue is true, returns
true to hide the inactive InitialValue
property.
methods (Access = protected) function flag = isInactivePropertyImpl(obj,propertyName) if strcmp(propertyName,'InitialValue') flag = obj.UseRandomInitialValue; else flag = false; end end end
Complete Class Definition File with Inactive Properties Method
classdef Counter < matlab.System % Counter Increment a counter % These properties are nontunable. They cannot be changed % after the setup method has been called or when the % object is running. properties (Nontunable) % Allow the user to set the initial value UseRandomInitialValue = true InitialValue = 0 end % The private count variable, which is tunable by default properties (Access = private) pCount end methods (Access = protected) % Increment the counter and return its value % as an output function c = stepImpl(obj) obj.pCount = obj.pCount + 1; c = obj.pCount; end % Reset the counter to either a random value or the initial % value. function resetImpl(obj) if obj.UseRandomInitialValue obj.pCount = rand(); else obj.pCount = obj.InitialValue; end end % This method controls visibility of the object's properties function flag = isInactivePropertyImpl(obj,propertyName) if strcmp(propertyName,'InitialValue') flag = obj.UseRandomInitialValue; else flag = false; end end end end