Main Content


Get the discrete states of a System object



    discreteStates= getDiscreteState(obj)returns a struct discreteStates of internal state value properties, which have the DiscreteState attribute. The field names of the struct are the object’s DiscreteState property names. You can restrict or change the values returned by getDiscreteState method by overwriting the getDiscreteStateImpl method.


    collapse all

    Use the getDiscreteStateImpl method in your class definition file to customize the behavior of getDiscreteState method. The System object contains discrete states value and power. A nontunable parameter keepTrackdetermines the states displayed by this method.

    Declare the behavior of getDiscreteState using getDiscreteStateImpl method in the class definition file.

    methods (Access = protected)
       function s = getDiscreteStateImpl(obj)
            if obj.keepTrack
                s.value = obj.value;
                s.power = obj.power; 
                s.value = obj.value; 

    Use getDiscreteState to access the discrete states of the method.

    discreteStates = getDiscreteState(obj);

    Input Arguments

    collapse all

    System object handle used to access properties, states, and methods specific to the object.

    Output Arguments

    collapse all

    Discrete state values returned as a struct.

    Version History

    Introduced in R2012b