| Contents | Index |
| On this page… |
|---|
Comparison of Variables with Inspection Displays Functions That Return Debugging Information in Variables How to Create Variables Using State Inspection Functions |
State inspection functions in the SimEvents debugger enable you to view information in the Command Window, as the sections Inspecting Entities, Blocks, and Events and Viewing the Event Calendar describe. An alternative way to capture the same information is in a variable in the MATLAB base workspace. Capturing information in a workspace variable lets you accomplish these goals:
Use information from one command as an input to another command, without having to type or paste information from the Command Window.
Cache information at a certain point in the simulation, for comparison with updated information at a later point in the simulation. The workspace variable remains fixed as the simulation proceeds.
Store information in a MAT-file and use it in a different MATLAB software session.
The table lists state inspection functions that can return variables in the workspace.
| Function | Returns | Class |
|---|---|---|
| blkinfo | Block information | Structure |
| blklist | Blocks and their identifiers | Cell |
| eninfo | Entity information | Structure |
| evcal | Event calendar | Structure |
| evinfo | Event information | Structure |
| gceb | Path name of the block associated with the current operation | String (char) |
| gcebid | Identifier of the block associated with the current operation | String (char) |
| gcen | Identifier of the entity that undergoes the current operation | String (char) |
| gcev | Identifier of the event associated with the current operation | String (char) |
| simtime | Current simulation time | Numeric (double) |
To create a variable using a state inspection function, follow these rules:
Name an output variable in the syntax that you use to invoke the function, such as my_entity_id = gcen. The function creates the output variable in the workspace.
If the function requires input arguments, express them using the functional form of the syntax, such as evinfo('ev1'), rather than the command form, evinfo ev1.
To learn about functional and command forms of syntax, see Command vs. Function Syntax.
To learn how to formulate input arguments for blkinfo, eninfo, and evinfo, see Obtaining Identifiers of Entities, Blocks, and Events.
For details about the information each function returns in the output variable, see the corresponding function reference page.
Full details about structures and cell arrays are in Structures and Cell Arrays. Tips that you might find useful for working with the variables that debugger functions return are:
If a cell array shows something like [1x51 char] instead of exact block path names when you enter the variable name alone at the command prompt, use content indexing to display the cell contents explicitly. Content indexing uses curly braces, {}. For an example, see the sedb.blklist reference page.
To access information in nested structures, append nested field names using dot notation. For an example, see the sedb.eninfo reference page.
You can assign numeric values of like-named fields in a structure array to a numeric vector. To do this, enclose the array.field expression in square brackets, []. For an example, see the sedb.evcal reference page.
You can assign string values of like-named fields in a structure array to a cell array. To do this, enclose the array.field expression in curly braces, {}. For examples, see the sedb.blkinfo and sedb.breakpoints reference pages.
You can gather information about like-named fields in a structure array that satisfy certain criteria, by invoking find and using its output to index into the structure array. For examples, see the sedb.evcal and sedb.breakpoints reference pages.
This example illustrates ways that you can use information from one command as an input to another command. Suppose your system includes several server blocks and you want to see how many entities are in each server block that is currently busy serving an entity. The following code inspects the event calendar to locate service completion events, uses the events to locate server blocks that are currently busy, and inspects server blocks to find out how many entities are in them. An entity in the server might be in service or waiting to depart.
Begin a debugger session for a particular model by entering this command at the MATLAB command prompt:
sedebug('sedemo_star_routing')Proceed in the simulation. At the sedebug>> prompt, enter:
tbreak 5 cont
The output ends with a message describing the context of the simulation shortly after T = 5:
Hit b1 : Breakpoint for first operation at or after time 5.000000 %==============================================================================% Executing ServiceCompletion Event (ev29) Time = 5.189503930558476 : Entity = en4 Priority = 5 : Block = Distribution Center/Infinite Server
To find out how many entities are in each server that is currently busy serving, use a series of state inspection and variable manipulation commands:
% Get the event calendar.
eventcalendar = evcal;
% Combine executing and pending events, to search both.
allevents = [eventcalendar.ExecutingEvent; eventcalendar.PendingEvents];
% Find service completion events.
idx = cellfun(@(x) isequal(x,'ServiceCompletion'), {allevents.EventType});
svc_completions = allevents(idx);
% Find the unique server blocks.
svrs = unique({svc_completions.Block});
% Compute the number of server blocks.
num = length(svrs);
% Preallocate an array for the results.
n = zeros(1,num);
% Loop over the server blocks and find the number of entities
% in each block.
for jj=1:num
s = blkinfo(svrs{jj});
n(jj)=length(s.Entities);
disp(sprintf('%s: %d',svrs{jj},n(jj)))
end
The output is:
sedemo_star_routing/Distribution Center/Infinite Server: 1 sedemo_star_routing/Service Station 3/Infinite Server3: 1 sedemo_star_routing/Service Station 4/Infinite Server4: 2
End the debugger session. At the sedebug>> prompt, enter:
sedb.quit
![]() | Inspecting Entities, Blocks, and Events | Viewing the Event Calendar | ![]() |

Model electronic system architectures, process flows, and logistics as queuing systems or agent-based systems.
Get free kit| © 1984-2012- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |