This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

Define Property Attributes

This example shows how to specify property attributes.

Property attributes, which add details to a property, provide a layer of control to your properties. In addition to the MATLAB® property attributes, System objects can use these three additional attributes—nontunable, logical, and positiveInteger. To specify multiple attributes, separate them with commas.

Specify Property as Nontunable

Use the nontunable attribute for a property when the algorithm depends on the value being constant once data processing starts. Defining a property as nontunable may improve the efficiency of your algorithm by removing the need to check for or react to values that change. For code generation, defining a property as nontunable allows the memory associated with that property to be optimized. You should define all properties that affect the number of input or output ports as nontunable.

System object™ users cannot change nontunable properties after the setup method has been called or while the object is running. In this example, you define the InitialValue property, and set its value to 0.

properties (Nontunable)
   InitialValue = 0;

Specify Property as Logical

Logical properties have the value, true or false. System object users can enter 1 or 0 or any value that can be converted to a logical. The value, however, displays as true or false. You can use sparse logical values, but they must be scalar values. In this example, the Increment property indicates whether to increase the counter. By default, Increment is tunable property. The following restrictions apply to a property with the Logical attribute,

  • Cannot also be Dependent or PositiveInteger

  • Default value must be true or false. You cannot use 1 or 0 as a default value.

properties (Logical)
   Increment = true 

Specify Property as Positive Integer

In this example, the private property MaxValue is constrained to accept only real, positive integers. You cannot use sparse values. The following restriction applies to a property with the PositiveInteger attribute,

  • Cannot also be Dependent or Logical

properties (PositiveInteger)

Specify Property as DiscreteState

If your algorithm uses properties that hold state, you can assign those properties the DiscreteState attribute . Properties with this attribute display their state values when users call getDiscreteStateImpl via the getDiscreteState method. The following restrictions apply to a property with the DiscreteState attribute,

  • Numeric, logical, or fi value, but not a scaled double fi value

  • Does not have any of these attributes: Nontunable, Dependent, Abstract, Constant, or Transient.

  • No default value

  • Not publicly settable

  • GetAccess = Public by default

  • Value set only using the setupImpl method or when the System object is locked during resetImpl or stepImpl

In this example, you define the Count property.

properties (DiscreteState)

Complete Class Definition File with Property Attributes

classdef Counter < matlab.System
% Counter Increment a counter to a maximum value

  % These properties are nontunable. They cannot be changed 
  % after the setup method has been called or while the
  % object is running.
  properties (Nontunable)
      % The inital value of the counter
      InitialValue = 0
  properties (Nontunable, PositiveInteger)
      % The maximum value of the counter
      MaxValue = 3
  properties (Logical)
      % Whether to increment the counter
      Increment = true
  properties (DiscreteState)
      % Count state variable
  methods (Access = protected)
      % Increment the counter and return its value
      % as an output
      function c = stepImpl(obj)
          if obj.Increment && (obj.Count < obj.MaxValue)
              obj.Count = obj.Count + 1;
              disp(['Max count, ' num2str(obj.MaxValue) ',reached'])            
          c = obj.Count;
      % Setup the Count state variable
      function setupImpl(obj)
          obj.Count = 0;
      % Reset the counter to one.
      function resetImpl(obj)
          obj.Count = obj.InitialValue;

More About

Was this topic helpful?