Products & Services Solutions Academia Support User Community Company

Learn more about SimEvents   

Setting Attributes of Entities

Role of Attributes in SimEvents Models

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 length.

In some modeling situations, it is important to attach data to an entity instead of merely creating the data as the content of a signal. The next example shows the importance of considering not only the topology of your block diagrams, but also the timing of data signals.

Example: Reusing Data

Consider a queue-server example (open model) with varying service times. Suppose you want to plot the service time against entity count for each entity departing from the server. A 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.

Blocks That Set Attributes

To assign attributes on each arriving entity, use one of the blocks in the next table.

BlockAttribute ValueFor More Information
Attribute FunctionValue of output argument from a function you writeWriting Functions to Manipulate Attributes
Set AttributeSignal value or information you enter in the block dialog boxSet Attribute block reference page
Entity Departure CounterEntity count, only if you set Write count to attribute to On.Associating Each Entity with Its Index
Single ServerResidual service time, only for preempted entitiesPreempting an Entity in a Server

Assignments can create new attributes or change the values of existing attributes.

To learn how to query entities for attribute values, see Accessing Attributes of Entities. To learn how to aggregate attributes from distinct entities, see Combining Entities.

Attribute Value Support

These lists summarize the characteristics of attribute values.

Permitted Characteristics of Attribute Values

For a given attribute, the characteristics of the value must be consistent throughout the model.

Not Permitted as Attribute Values

Example: Setting Attributes

This example (open model) illustrates different ways of assigning attribute values to entities.

After each entity departs from the Attribute Function block, it possesses the attributes listed in the table.

Attribute NameAttribute ValueMethod for Setting Attribute Value
CountN, for the Nth entity departing from the Time-Based Entity Generator blockIn Entity Departure Counter dialog box:
Write count to attribute = On
Attribute name = Count

Actually, the entity generator creates the Count attribute with a value of 0. The Entity Departure Counter block sets the attribute value according to the entity count.

TypeConstant value of 3A1 row of table in Set Attribute dialog box:
Name = Type
Value From = Dialog
Value = 3
LengthNext number in the sequence produced by Event-Based Sequence blockEvent-Based Sequence block connected to Set Attribute block in which A2 row of table in dialog box is configured as follows:
Name = Length
Value From = Signal port
LengthIntfloor(Length)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, and the Length values show cyclic repetition of a sequence. For brevity, the example does not plot LengthInt values, which would look similar to Length values.

  


Related Products & Applications

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.

 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS