iterate

Class: matlab.DiscreteEventSystem
Package: matlab

Event action when entity iterates

Syntax

[entity,events,next]=iterate(obj,storage,entity,tag,cur)
[entity,events,next,out1,...]=iterate(obj,storage,entity,tag,cur,in1,...)

Description

[entity,events,next]=iterate(obj,storage,entity,tag,cur) specifies event actions for when an entity is processed as a part of an iterate event.

[entity,events,next,out1,...]=iterate(obj,storage,entity,tag,cur,in1,...) specifies such event actions 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 currently being processed. 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 iterate event.

MATLAB structure indicating current state of iteration. The structure has these fields:

  • size

    Total number of entities the storage has

  • position

    Position of the current iterating entity

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

Output Arguments

expand all

Entity being processed, possibly with changed data.

Events to be scheduled after the method returns. 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

  • True

    Continue to process the next entity in the storage element.

  • False

    Terminate the iterate event, and leave the rest of the entities of the storage element unprocessed.

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

Examples

expand all

Forward the first entity with matching data value to output port 1 of the discrete-event system.

function [entity,events,next] = iterate(obj,storage,entity,tag,status)
    % Forward the first entity with matching data value to output
    % port 1 of the discrete-event system.
    disp(['Searching in storage element ' num2str(storage)]);
    disp(['    Total size = ' num2str(status.size)]);
    disp(['    Current position = ' num2str(status.position)]);
    if (entity.data == obj.dataToSearch)
        events = obj.eventForward('output', 1, 0);
        next = false;   % Found -- early terminate
    else
        events = [];
        next = true;    % Not yet found -- continue
    end
end

Introduced in R2016a