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
[
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
Output Arguments
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