Main Content

Enable For Each Subsystem Support

Enable For Each subsystem support by using a System object™ in a Simulink® For Each subsystem. Include the supportsMultipleInstanceImpl method in your class definition file. This method applies only when the System object is used in Simulink via the MATLAB System block.

Use the supportsMultipleInstanceImpl method and have it return true to indicate that the System object supports multiple calls in a Simulink For Each subsystem.

methods (Access = protected)
   function flag = supportsMultipleInstanceImpl(obj)
       flag = true;
   end
end

View the method in the complete class definition file.

classdef RandSeed < matlab.System
% RANDSEED Random noise with seed for use in For Each subsystem
  
    properties (DiscreteState)
       count;
    end
    
    properties (Nontunable)
       seed = 20;
       useSeed (1,1) logical = false;
    end

   methods (Access = protected)
       function y = stepImpl(obj,u1)
         % Initial use after reset/setup 
         % and use the seed
         if (obj.useSeed && ~obj.count)
             rng(obj.seed);
         end
         obj.count = obj.count + 1;
         [m,n] = size(u1);
         % Uses default rng seed
         y = rand(m,n) + u1;
       end
      
      function setupImpl(obj)
          obj.count = 0;
      end
      function resetImpl(obj)
          obj.count = 0;
      end
       
       function flag = supportsMultipleInstanceImpl(obj)
         flag = obj.useSeed;
       end
   end
end

See Also

Classes

Functions