Using the Simulink Debugger (Example 2)

by

 

02 Feb 2004 (Updated )

Explores using the Simulink Debugger to extract information.

example2.m
%% Example2.m
%
% This MATLAB script file will show the following:
%
% # Leverage the Simulink Debugger to interrogate information on simulation
%      execution in a batched manner (usually done interactively).
% # Use Simulink Debugger to specifically access failed step information
%      when using variable step solvers, specifically identifying the
%      limiting state causing the failure.
% # Parse Debugger information to replace with Simulink's state
%      definition or user defined state definition.
%
% ADVICE: Did you know you can use the MATLAB debugger to step through
%         this file line by line!  WOW!

% Copyright 2004 - 2010 The MathWorks, Inc.
%% Clean up current session
bdclose all
clear all

% check if a solvertrace.txt file exists, deleting so as not to append
% info.
if(exist('solvertrace.txt'))
    disp('Deleting solvertrace.txt')
    delete('solvertrace.txt')
end

%% lets look at the VDP model
% The following model is a modified VDP model with the accelerator turned on.
% Look inside the GETTRACE command for more information on this decision.
%
getstrace('vdp_debug')

out = parsestrace('solvertrace.txt')

%% Exercises
%
% Look at all the useful information that the Simulink Debugger can get
% you!  Reference the Simulink Debugger Command reference in the
% documentation.
%
% Refer to the great Simulink Debugger Section in the documentation!
% http://www.mathworks.com/access/helpdesk/help/toolbox/simulink/ug/debug.shtml
% web([docroot '/toolbox/simulink/ug/debug.html'])
%
% EXERCISE 1:
% Can you use the debugger to find out how hard Simulink is working to
% solve the Algebraic Loop in the HYDCYL Simulink model!!  Can you also
% have the Simulink Debugger highlight all the blocks that constitute the
% algebraic loop!
%
% HINT:
%  - do this interactively through the GUI and MATLAB command line
%  - see Simulink Debugger command ATRACE!
%  - see Simulink Debugger command ASHOW!
%
% EXERCISE 2:
% Can you use the Simulink Debugger to see the block execution order of the
% ONECART Simulink model!
%
% HINT:
%  - do this interactively through the GUI and the MATLAB command line
%  - in the Simulink Debugger GUI see the Sorted List Tab
%  - or use the SLIST command
%
% EXERCISE 3:
% Can you write your own batched Simulink Debugger run that writes out to a
% file the complete sorted lists of model AERO_DAP3DOF!
%
% HINT:
%  - Copy GETSTRACE to your own GETSLIST and begin modifying it.
%  - use command SLIST within the batched Debugger commands.
%  - You do not need to run the simulation!  Only bring up the debugger
%    run the SLIST command, and get out of the debugger.

Contact us