Documentation

Set Output Size

This example shows how to specify the size of a System object™ output using the getOutputSizeImpl method. Use this method when Simulink® cannot infer the output size from the inputs during model compilation.

    Note:   For variable-size inputs, the propagated input size from propagatedInputSizeImpl differs depending on the environment.

    • MATLAB® — When you first run an object, it uses the actual sizes of the inputs.

    • Simulink — The maximum of all the input sizes is set before the model runs and does not change during the run.

Subclass from both the matlab.System base class and the Propagates mixin class.

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

Use the getOutputSizeImpl method to specify the output size.

methods (Access = protected)
   function sizeout = getOutputSizeImpl(~)
      sizeout = [1 1];
   end
end

View the method in the complete class definition file.

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 y = stepImpl(obj,u1,u2)
         % Add to count if u1 is above threshold
         % Reset if u2 is true
         if (u2)
           obj.Count = 0;
         elseif (any(u1 > obj.Threshold))
           obj.Count = obj.Count + 1;
         end
         y = obj.Count;
      end
    
      function resetImpl(obj)
         obj.Count = 0;
      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
      function inLocked = isInputSizeLockedImpl(~,idx)
         if idx == 1
           inLocked = false;
         else
           inLocked = true;
         end
      end
   end
end

See Also

|

More About

Was this topic helpful?