Documentation

This is machine translation

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

Specify Whether Output Is Fixed- or Variable-Size

This example shows how to specify that System object™ output is fixed- or variable-size.

This example shows how to specify that a System object output is fixed-size. Fixed-size output is always the same size, while variable-size output can be different size vectors. isOutputSizeLockedImpl accepts the port index and returns true if the input size is locked (variable sized vectors are disallowed) and false if the input size is not locked (variable sized vectors are allowed). Use the isOutputFixedSizeImpl method when Simulink® cannot infer the output type from the inputs during model compilation.

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

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

Use the isOutputFixedSizeImpl method to specify that the output is fixed size.

methods (Access = protected)
   function fixedout = isOutputFixedSizeImpl(~)
      fixedout = true;
   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 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 [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

For a System object with variable-size output, you do not need to add any method to the class definition file because variable-size output is the default.

See Also

|

More About

Was this topic helpful?