generate

Class: matlab.DiscreteEventSystem
Package: matlab

Event action upon entity creation

Syntax

[entity,events]=generate(obj,storage,entity,tag)
[entity,events,out1,...]=generate(obj,storage,entity,tag,in1,...)

Description

[entity,events]=generate(obj,storage,entity,tag) specifies event actions of the object when an entity is created inside a storage component.

[entity,events,out1,...]=generate(obj,storage,entity,tag,in1,...) specifies such event actions of the object when the block has one or more input signal ports and/or signal output ports.

Input Arguments

expand all

Discrete-event System object.

Index of the storage element.

Entity to create inside storage element. Entity has these fields:

  • sys (MATLAB structure) — It has these fields:

    • id (double) — Entity ID

    • priority (double) — Entity priority

  • data — Entity data

Tag of the current entity generation event.

Any data inputs of the object. These input arguments exist only when the object has data inputs.

Output Arguments

expand all

Entities created with possibly changed values.

Events to be scheduled for just after entities are created. Use matlab.DiscreteEventSystem class methods to create events. Each event has these fields:

  • type (character vector) — Type of the event

  • delay (double) — Delay before the event

  • priority (double) — Priority of the event

  • Storage (double) — Index of the storage element

  • tag (character vector) — Event tag

  • location (MATLAB structure) — Source or destination location of entity

Data outputs of the object. You must specify these output arguments when the object has data outputs.

Examples

expand all

Initialize attribute values when entity is generated in a storage element.

function [entity,events] = generate(obj,storage,entity,tag)
    % Specify event actions when entity generated in storage.
    % - For entitiy generation event of tag 'Adam', initialize the
    %   entity so that its attribute 'gender' has value '0', and its
    %   priority is '200'.
    % - For entity generation event of tag 'Eve', initialize the
    %   entity so that its attribute 'gender' has value '1', and its
    %   priority is '100'.
    % - An event is returned to forward the entity to storage
    %   element 2 with a time delay of 0.6.
    switch tag
        case 'Adam'
            entity.data.gender = 0;
            entity.sys.priority = 200;
        case 'Eve'
            entity.data.gender = 1;
            entity.sys.priority = 100;
    end
    events = obj.eventForward('storage',2,0.6);
end

Introduced in R2016a