Main Content


Class: matlab.DiscreteEventSystem
Package: matlab

Initialize a resource specification array


resArray = initResourceArray()


resArray = initResourceArray() initializes an empty array of resourceSpecification. This method enables you to append elements to the array in the MATLAB Discrete-Event System block when you select the Code generation for the Simulate using parameter.

Output Arguments

expand all

Resource specifications specified as an empty array.


expand all

An entity entry to the storage element invokes two timer events. resourceSpecification defines the type and the amount of resources an entity acquires. The entity acquires a resource of type Test1 if the timer with tag ProcessComplete expires. The entity acquires a resource of type Test2 if the timer with tag TimeOut expires. The resRequest array is initialized by the initResourceArray method for code generation.

function [entity,event] = entry(obj,storage,entity,source)
  % Specify event actions when entity enters storage.
  ProcessingTime=randi([1 15]);
  % Define two timer events.
  event1 = obj.eventTimer('TimeOut',10);
  event2 = obj.eventTimer('ProcessComplete', ProcessingTime);   
  event=[event1 event2];

function [entity, event] = timer(obj,storage,entity,tag)
  % Specify event actions when a timer expires. 
  resRequest = obj.initResourceArray();
  switch tag
    case 'ProcessComplete'
      resRequest = obj.resourceSpecification('Test1', 1);  
    case 'TimeOut'
      resRequest = obj.resourceSpecification('Test2', 1); 
  event = obj.eventAcquireResource(resRequest, 'MyResourceAcquireEvent');

Version History

Introduced in R2019a