This example shows how to use a Simulink® Real-Time™ log of signal data and the Simulation Data Inspector. Signals are logged during model execution. At the end of the run, the Simulation Data Inspector interface displays the signal. This example show how to get the signals from the Simulation Data Inspectore interface by using the command line.
Open the model slrt_ex_soc_dist
. This model calibrates the control efforts through social distancing on an infectious disease outbreak.
Open the model.
mdl = 'slrt_ex_soc_dist'; mdlOpen = 0; systems = find_system('type', 'block_diagram'); if all(~strcmp(mdl, systems)) mdlOpen = 1; open_system(fullfile(matlabroot,'toolbox','slrealtime','examples','slrt_ex_soc_dist.slx')); end
Build the model and download to the target computer:
Configure for a non-Verbose build.
Build and download application.
set_param(mdl,'RTWVerbose','off'); slbuild(mdl);
### Generated code for 'slrt_ex_soc_dist' is up to date because no structural, parameter or code replacement library changes were found. ### Successful completion of build procedure for: slrt_ex_soc_dist ### Created MLDATX ..\slrt_ex_soc_dist.mldatx Build Summary 0 of 1 models built (1 models already up to date) Build duration: 0h 0m 7.325s
Close the model it is open.
if (mdlOpen) bdclose(mdl); end
Using the Simulink Real-Time object variable, tg
, load and start the model, and modify model parameters.
tg = slrealtime; tg.load(mdl); tg.setparam('','soc_dist_level',1); tg.setparam('','thresh_int_level',1); tg.start; while ~strcmp(tg.status,'stopped') pause(5); end tg.stop;
Using the Simulink Real-Time object variable, tg
, load and start the model, and modify model parameters
tg = slrealtime; tg.load(mdl); tg.setparam('','soc_dist_level',0.2); tg.setparam('','thresh_int_level',0.2); tg.start; while ~strcmp(tg.status,'stopped') pause(5); end tg.stop;
To view the plotted signal data, open the Simulation Data Inspector.
Simulink.sdi.view
You can also retrieve the signal data from the SDI and plot the data by using these commands.
Get all the runs
Get the run information
Get the signal.
Get the signal objects.
Take only infectious group values.
Plot the signals.
The result shows that social distancing can reduce the number of hospitalized people
runIds = Simulink.sdi.getAllRunIDs(); for i = 1:length(runIds) run = Simulink.sdi.getRun(runIds(i)); signalID = run.getSignalIDsByName('hospitalized'); if ~isempty(signalID) signalObj = Simulink.sdi.getSignal(signalID); signalArray(:,i) = signalObj.Values(:,1).Data; timeValues = 100*(signalObj.Values(:,1).Time); plot(timeValues,signalArray); drawnow; end end grid on; xlabel('Time in days'); ylabel('hospitalized people');
SLRT Overload
Options | slrtTETMonitor