Documentation Center

  • Trial Software
  • Product Updates

Set Output Data Type

This example shows how to specify the data type of a System object™ output using the getOutputDataTypeImpl method. This method indicates the data type of the output when the data type cannot be inferred from the inputs during Simulink® model compilation.

Subclass from the Propagates Mixin Class

To use the getOutputDataTypeImpl method, you must subclass from the Propagates mixin class.

 classdef CounterReset < matlab.System & ...
     matlab.system.mixin.Propagates

Specify Output Data Type

Use the getOutputDataTypeImpl method to specify the output data type as a double.

methods (Access=protected)
   function dataout = getOutputDataTypeImpl(~)
      dataout = 'double';
   end
end

Complete Class Definition File with Specified Output Data Type

classdef CounterReset < matlab.System & matlab.system.mixin.Propagates
   %CounterReset Count values above a threshold
    
   properties
      Threshold = 1
   end
  
   properties (DiscreteState)
      Count
   end
  
   methods (Access=protected)
      function setupImpl(obj,~,~)
         obj.Count = 0;
      end
    
      function resetImpl(obj)
         obj.Count = 0;
      end
    
      function y = stepImpl(obj,u1,u2)
         % Add to count if u1 is above threshold
         % Reset if u2 is true
         if (u2)
            obj.Count = 0;
         elseif (u1 > obj.Threshold)
            obj.Count = obj.Count + 1;
         end
         y = obj.Count;
      end
    
      function N = getNumInputsImpl(~)
         N = 2;
      end
          
      function [sz,dt,cp] = getDiscreteStateSpecificationImpl(~,name)
         if strcmp(name,'Count')
            sz = [1 1];
            dt = 'double';
            cp = false;
         else
            error(['Error: Incorrect State Name: 'name'.']);
         end
      end
      function dataout = getOutputDataTypeImpl(~)
         dataout = 'double';
      end
      function sizeout = getOutputSizeImpl(~)
         sizeout = [1 1];
      end
      function cplxout = isOutputComplexImpl(~)
         cplxout = false;
      end
      function fixedout = isOutputFixedSizeImpl(~)
         fixedout = true;
      end
   end
end

See Also

|

More About

Was this topic helpful?