You can attach data to an entity using one or more attributes of the entity. Each attribute has a name and a numeric value. You can read or change the values of attributes during the simulation.
For example, suppose your entities represent a message that
you are transmitting across a communication network. You can attach
the length of each particular message to the message itself, using
an attribute named
You can also use attributes to specify the amount of a resource for your model. For more information, see Model with Resources.
To attach attributes to an entity, use one of the blocks listed in the following table. Attribute attachments can create new attributes or change the values of existing attributes.
|Data to Attach||Blocks to Use||More Information and Examples|
|Constant value||Set Attribute|
|Random numbers||Event-Based Random Number followed by Set Attribute|
|Elements of either a vector in the MATLAB® workspace or a vector that you can type in a block dialog box||Event-Based Sequence followed by Set Attribute|
|Values of an output argument of a MATLAB function that you write||Attribute Function, or MATLAB Function followed by Set Attribute|
|Values of an event-based signal||Set Attribute|
|Values of a time-based signal||Set Attribute preceded by Timed to Event Signal|
|Entity count||Entity Departure Counter with Write count to attribute check box selected|
After each entity departs from the Attribute Function block, it possesses the attributes listed in the table.
|Attribute Name||Attribute Value||Method for Setting Attribute Value|
|N, for the Nth entity departing from the Time-Based Entity Generator block||In Entity Departure Counter dialog box:|
Actually, the entity generator creates the
|Constant value of ||A1 row of table in Set Attribute dialog
|Next number in the sequence produced by Event-Based Sequence block||Event-Based Sequence block connected to Set
Attribute block in which A2 row of table
in dialog box is configured as follows: |
|floor(||Attribute Function block whose function is|
function [out_LengthInt] = fcn(Length) out_LengthInt = floor(Length);
In this example, each Attribute Scope block plots
values of a different attribute over time. Notice from the vertical
axes of the plots below that the
Count values increase
by 1 with each entity, the
Type values are constant,
Length values show cyclic repetition of
a sequence. For brevity, the example does not plot
which would look similar to
In some modeling situations, it is important to attach data to an entity instead of using a signal directly. This example (open modelmodel) shows the importance of considering not only the topology of your block diagrams, but also the timing of data signals.
The model contains a server with varying service times. Suppose you want to plot the service time against entity count for each entity departing the server. A ramp signal specifies the service time to use for each entity. Although connecting the same signal to the Signal Scope block appears correct topologically, the timing in such an arrangement is incorrect. The incorrectness arises from the delay at the server. That is, the signal has one value when a given entity arrives at the server and another value when the same entity arrives at the scope.
To implement the example correctly, attach the service time to each entity using an attribute and retrieve the attribute value when needed from each entity. That way, the scope receives the service time associated with each entity, regardless of the delay between arrival times at the server and the scope.