Documentation Center

  • Trial Software
  • Product Updates

Hide Inactive Properties

This example shows how to hide the display of a property that is not active for a particular object configuration.

Hide an inactive property

You use the isInactivePropertyImpl method to hide a property from displaying. If the isInactiveProperty method returns true to the property you pass in, then that property does not display.

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 Hidden Inactive Property

classdef Counter < matlab.System
  %Counter Increment a counter
  
  % These properties are nontunable. They cannot be changed
  % after the setup or step method has been called.
  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)
    % In step, 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

    % The step method takes no inputs
    function numIn = getNumInputsImpl(~)
      numIn = 0;
    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

See Also

Was this topic helpful?