Skip to Main Content Skip to Search
Product Documentation

Working with Debugging Information in Variables

Comparison of Variables with Inspection Displays

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:

Functions That Return Debugging Information in Variables

The table lists state inspection functions that can return variables in the workspace.

FunctionReturnsClass
blkinfoBlock informationStructure
blklistBlocks and their identifiersCell
eninfoEntity informationStructure
evcalEvent calendarStructure
evinfoEvent informationStructure
gcebPath name of the block associated with the current operationString (char)
gcebidIdentifier of the block associated with the current operationString (char)
gcenIdentifier of the entity that undergoes the current operationString (char)
gcevIdentifier of the event associated with the current operationString (char)
simtimeCurrent simulation timeNumeric (double)

How to Create Variables Using State Inspection Functions

To create a variable using a state inspection function, follow these rules:

For details about the information each function returns in the output variable, see the corresponding function reference page.

Tips for Manipulating Structures and Cell Arrays

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:

Example: Finding the Number of Entities in Busy Servers

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.

  1. Begin a debugger session for a particular model by entering this command at the MATLAB command prompt:

    sedebug('sedemo_star_routing')
  2. 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
  3. 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
  4. End the debugger session. At the sedebug>> prompt, enter:

    sedb.quit

  


Free Discrete Event Simulation Technical Kit

Model electronic system architectures, process flows, and logistics as queuing systems or agent-based systems.

Get free kit

Trials Available

Try the latest version of discrete-event simulation products.

Get trial software
 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS