MATLAB: How to prevent an opened model from navigating back to the top level after running simulation with Coverage Analysis in Simulink Verification and Validation R2013b

analysiscoveragemodelnavigationsimulinkSimulink CheckSimulink Coverage

I have my Simulink model opened and navigated to a lower level. I ran the simulation with Coverage Analysis enabled. After the simulation, my model window navigated back to the top level. How can I make the model window stay at the level I am at before the simulation?

Best Answer

This is a behavior in old releases before MATLAB R2014a. In newer releases, the Simulink window will stay at the same level you are at after the simulation run.
Therefore, upgrading to a newer version is one of the choices to overcome this inconvenience. For MATLAB R2013b and earlier, a workaround would be invoking the simulation from a test script and programmatically navigate to the desired model level. For example, in the following code, the 'sldemo_clutch' model is simulated and analyzed for coverage. Before the simulation, we are focusing inside the subsystem 'Unlocked'. Simulation runs and reverts the navigation level to the top. We re-navigate back to the 'Unlocked' subsystem by using the 'open_system' command again. Since the simulation takes a while and the reverting to top model level happens after the simulation, we use the 'pause' command to wait and navigate back after the reverting.
 
mdl = 'sldemo_clutch';
open_system(mdl);
set_param(mdl, 'RecordCoverage','on');
set_param(mdl, 'CovMetricSettings','dcmtrzoib');
open_system([mdl,'/Unlocked']);
set_param(mdl, 'SimulationCommand', 'start'); % run simulation
pause(1); % wait for simulation and the navigation reverting to finish
open_system([mdl,'/Unlocked']); % navigate back to the subsystem