Documentation Center

  • Trial Software
  • Product Updates

Set Output Complexity

This example shows how to specify whether a System object™ output is a complex or real value. You use the isOutputComplexImpl method when the output complexity cannot be inferred from the inputs during Simulink® model compilation.

Subclass from the Propagates Mixin Class

To use the isOutputComplexImpl method, you must subclass from both the matlab.System base class and the Propagates mixin class.

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

Specify Output Complexity

Use the isOutputComplexImpl method to specify that the output is real.

methods (Access=protected)
   function cplxout = isOutputComplexImpl(~)
      cplxout = false;
   end
end

Complete Class Definition File with Specified Complexity

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?