generate
Class: matlab.DiscreteEventSystem
Namespace: matlab
Event action upon entity creation
Syntax
[entity,events]=generate(obj,storage,entity,tag)
[entity,events,out1,...]=generate(obj,storage,entity,tag,in1,...)
Description
[
specifies event actions of the object when an entity is created inside a storage
component. entity
,events
]=generate(obj
,storage
,entity
,tag
)
[
specifies such event actions of the object when the block has one or more input signal
ports and/or signal output ports.entity
,events
,out1
,...]=generate(obj
,storage
,entity
,tag
,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 to create inside storage element. 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 generation event.
in1
— 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
Entities created with possibly changed values.
events
— Events
vector of MATLAB structures
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 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
out1
— Data output
any value
Data outputs of the object. You must specify these output arguments when the object has data outputs.
Examples
Set Initial Values When Entity is Generated
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
Create a Custom Block to Generate Entities
This example shows how to create a custom source block that generates entities and to manage discrete states when implementing the discrete-event System object methods.
For more information, see Custom Entity Generator Block with Signal Input and Signal Output.
classdef CustomEntityStorageBlockGeneration < matlab.DiscreteEventSystem... & matlab.System % A custom entity generator block. % Nontunable properties properties (Nontunable) % Generation period period = 1; end properties(DiscreteState) % Entity priority priority; % Entity value value; end % Discrete-event algorithms methods function [events, out1] = setupEvents(obj) % Set up entity generation events at simulation start. events = obj.eventGenerate(1,'mygen',obj.period,obj.priority); % Set up the initial value of the output signal. out1 = 10; end function [entity,events,out1] = generate(obj,storage,entity,tag,in1) % Specify event actions when entity is generated in storage. entity.data = obj.value; % The priority value is assigned from the input signal. obj.priority = in1; % Output signal is the assigned priority value. out1 = obj.priority; events = [obj.eventForward('output',1,0) ... obj.eventGenerate(1,'mygen',obj.period,obj.priority)]; end end methods(Access = protected) function entityTypes = getEntityTypesImpl(obj) entityTypes = obj.entityType('Material'); end function [inputTypes,outputTypes] = getEntityPortsImpl(obj) % Specify entity input and output ports. Return entity types at % a port as strings in a cell array. Use empty string to % indicate a data port. inputTypes = {''}; outputTypes = {'Material',''}; end function resetImpl(obj) % Initialize / reset discrete-state properties. obj.priority = 10; obj.value = 1:12; end function [storageSpecs, I, O] = getEntityStorageImpl(obj) storageSpecs = obj.queueFIFO('Material', 1); I = 0; O = [1 0]; end function num = getNumInputsImpl(obj) % Define total number of inputs for system with optional % inputs. num = 1; end function num = getNumOutputsImpl(~) % Define total number of outputs. num = 2; end function [out1 out2] = getOutputSizeImpl(obj) % Return size for each output port. out1 = [1 12]; out2 = 1; end function [out1 out2] = getOutputDataTypeImpl(obj) % Return data type for each output port. out1 = "double"; out2 = "double"; end function [out1 out2] = isOutputComplexImpl(obj) % Return true for each output port with complex data. out1 = false; out2 = false; end function [sz,dt,cp] = getDiscreteStateSpecificationImpl(obj,name) % Return size, data type, and complexity of discrete-state % specified in name. switch name case 'priority' sz = [1 1]; case 'value' sz = [1 12]; end dt = "double"; cp = false; end end end
Version History
Introduced in R2016a
Commande MATLAB
Vous avez cliqué sur un lien qui correspond à cette commande MATLAB :
Pour exécuter la commande, saisissez-la dans la fenêtre de commande de MATLAB. Les navigateurs web ne supportent pas les commandes MATLAB.
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)