eventIterate
Class: matlab.DiscreteEventSystem
Namespace: matlab
Create entity iterate event
Syntax
event=eventIterate(storageID,tag,priority)
Description
creates an event to repeatedly process entities of a storage element. You can then
schedule this event by returning it as the output argument when implementing an event
action method, such as event
=eventIterate(storageID
,tag
,priority
)exit
.
Input Arguments
storageID
— Storage index
double
Index of a storage element. Entities inside this storage element will be iterated.
tag
— Tag
character vector
Custom tag of this entity iterate event.
priority
— Priority (optional)
double
Priority of the entity iterate event. This value must be a positive integer, where a smaller value indicates a higher event priority.
Output Arguments
event
— Event
MATLAB® structure
Event that processes entities of a specific storage element.
Examples
Iterate Entities of a Storage Element
Define an event to iterate entities of a storage element..
function event = exit(obj,storage,entity,dst) % Define an event to iterate entities of a storage element % - The event is regarding to storage element 2 % - The event has a custom tag 'search' % - The event shall be executed at current simulation clock time % - The event has a priority of 10 (a smaller numeric value % indicates a higher event priority) event = obj.eventIterate(2, 'search', 10); end
Custom Entity Storage Block with Iterate 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)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)