iterate
Class: matlab.DiscreteEventSystem
Namespace: 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
[
specifies event actions for when an entity is processed as a part of an iterate
event.entity
,events
,next
]=iterate(obj
,storage
,entity
,tag
,cur
)
[
specifies such event actions when the block has one or more input signal ports and/or
signal output ports.entity
,events
,...
next
,out1
,...]=iterate(obj
,storage
,entity
,tag
,cur
,in1
,...)
Input Arguments
obj
— Discrete-event System object™
MATLAB® object
Discrete-event System object.
storage
— Storage
double
Index of the storage element.
entity
— Entity
MATLAB structure
Entity currently being processed. Entity has these fields:
sys
(MATLABstructure
) — It has these fields:id
(double
) — Entity IDpriority
(double
) — Entity priority
data
— Entity data
tag
— Tag
character vector
Tag of the current entity iterate event.
cur
— Current state
MATLAB structure
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
in1
— Signal input
any value
Any data inputs of the object. These input arguments exist only when the object has data inputs.
Output Arguments
entity
— Entity
MATLAB structure
Entity being processed, possibly with changed data.
events
— Events
vector of MATLAB structures
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 eventdelay
(double
) — Delay before the eventpriority
(double
) — Priority of the eventStorage
(double
) — Index of the storage elementtag
(character vector
) — Event taglocation
(MATLABstructure
) — Source or destination location of entity
next
— Iteration
logical | double
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.
out1
— Signal output
any value
Data outputs of the object. You must specify these output arguments when the object has data outputs.
Examples
Forward the First Entity
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
Custom Entity Storage Block with Iteration Event
In this example, a custom block allows entities to enter its storage
element through its input port. The storage element is a priority queue that
sorts the entities based on their Diameter
attribute in
ascending order. Every entity entry to the block's storage invokes an
iteration event to display the diameter and the position of each entity in
the storage.
For more information, see Create a Custom Entity Storage Block with Iteration Event.
classdef CustomEntityStorageBlockIteration < matlab.DiscreteEventSystem % A custom entity storage block with one input port and one storage element. % Nontunable properties properties (Nontunable) % Capacity Capacity = 5; end % Create the storage element with one input and one storage. methods (Access=protected) function num = getNumInputsImpl(obj) num = 1; end function num = getNumOutputsImpl(obj) num = 0; end function entityTypes = getEntityTypesImpl(obj) entityType1 = obj.entityType('Wheel'); entityTypes = entityType1; end function [inputTypes,outputTypes] = getEntityPortsImpl(obj) inputTypes = {'Wheel'}; outputTypes={}; end function [storageSpecs, I, O] = getEntityStorageImpl(obj) storageSpecs = obj.queuePriority('Wheel',obj.Capacity, 'Diameter','ascending'); I = 1; O = []; end end % Entity entry event action methods function [entity, event] = WheelEntry(obj,storage,entity, source) % Entity entry invokes an iterate event. event = obj.eventIterate(1, ''); end % The itarate event action function [entity,event,next] = WheelIterate(obj,storage,entity,tag,cur) % Display wheel id, position in the storage, and diameter. coder.extrinsic('fprintf'); fprintf('Wheel id %d, Current position %d, Diameter %d\n', ... entity.sys.id, cur.position, entity.data.Diameter); if cur.size == cur.position fprintf('End of Iteration \n') end next = true; event=[]; end end end
Version History
Introduced in R2016a
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)