from
Using the Simulink Debugger (Example 2)
by Dan Lluch
Explores using the Simulink Debugger to extract information.
|
| getstrace(mdl,vargin)
|
function getstrace(mdl,vargin)
% GETSTRACE
%
% This function executes a preselected set of Simulink Debugger commands in
% order to batch the Simulink debugger execution. MDL is the model to
% perform this operation on. Optional argument TFINAL, can override the
% final time of the simulation run that is in the model.
%
% This will execute STRACE 4 on a passed in model and output the results to
% a file named SOLVERTRACE.TXT (as well as to the screen). It also records
% the output of the STATES command within the file.
%
% The information is appended if the file already exists.
% Copyright 2004 - 2010 The MathWorks, Inc.
% Load model if not loaded
open_bd = find_system('type', 'block_diagram');
if isempty(find(strcmp(open_bd,mdl)))
load_system(mdl);
end
if nargin>1
tfinal = vargin(1);
else
tfinal = [];
end
% Check if model is in accelerator mode
%
% NOTE: Running the Simulink Debugger can (and likely) changes some options
% that would require a rebuild form a non Simulink Debugger Accelerator
% runs. Thus one may see rebuilding occur between a simulation run within
% the Simulink Debugger immediately followed by a simulation run outside
% the Simulink Debugger.
%
% For large models, this can be avoided by
% 1) having a seperate model only used in debug accelerated build, or
% 2) having a seperate directory such that you keep the appropriate DLL
% for checksum matching, or
% 3) making the options exactly the same on the non debug model as used
% in the debug model (not advised).
% 4) running in accelerated mode is not useful for you in either case.
%
smode = get_param(mdl,'SimulationMode');
if (~strcmp(smode,'accelerator'))
disp(['simulation is in ' smode]);
disp(['Consider changing to Accelerated mode']);
end
% The batch list of debugging commands.
dbgcmds = {'strace 4', ...
'diary solvertrace.txt', ...
'cont', ...
'states',...
'diary off', ...
'cont'};
opts = simset('debug',dbgcmds);
sim(mdl,tfinal,opts);
|
|
Contact us at files@mathworks.com