For MATLAB R2022b and later:
Starting in R2022b, you can create multiple log files on your target machine by using either:
- The interactive Start/Stop Recording API (see Example 1 below), or
- An Enable File Log block driven by a control signal in your model (see Example 2 below).
Every time the file logging service is started using one of the above methods, it generates a new log file. When you import these files into the Simulation Data Inspector (SDI), each log appears as a separate run, corresponding to one experiment. For details on different ways to control file logging, see Start/Stop Recording API vs. Enable File Log block. There are several important points to consider when using this workflow:
- Ensure that the maximum number of file log runs (SLRTFileLogMaxRuns) is set to an appropriate number for your application. If needed, you can adjust this setting after you build the model.
- There will be gaps in the recorded data between stopping one file log and starting the next. Although these gaps should be small, they should be accounted for during data analysis and post‑processing.
- File log data cannot be imported while a log file is actively being written. You must stop the logging operation before attempting to import a particular file log.
- The logging service automatically stops when the available disk space on the target is less than 1GB. If this happens, the application will continue running, but no further logging will happen until you free up space. See also: How to avoid running out of disk space on my Speedgoat target computer with SLRT?
Example 1: Interactively create multiple file logs using the Start/StopRecoding API
The Start/Stop Recording API is available via the startRecording and stopRecording MATLAB functions, and via the 'Start Recording' and 'Stop Recording' buttons in the Simulink Toolstrip, SLRT Explorer, and custom SLRT apps. To familiarize yourself with the concept, run the following commands in the MATLAB command window one by one for the slrt_ex_osc example model: % Configure, build and load model
>> model = 'slrt_ex_osc';
>> open_system(model);
>> tg = slrealtime;
>> tg.configureModelForTargetPlatform(model);
>> evalc('slbuild(model)');
>> load(tg,model);
% Start model - Note that:
% * 'FileLogMaxRuns' is used store more than one log file for an application before overwriting.
% * 'autoImportFileLog' is disabled to import file logs on demand.
% * Logging starts automatically when using "start".
>> start(tg,'FileLogMaxRuns', 5, 'StopTime', Inf, 'autoImportFileLog', false);
% Wait for some time
>> stopRecording(tg);
>> startRecording(tg);
% Wait for some time
>> stopRecording(tg);
>> startRecording(tg);
% Inspect file log list:
>> list(tg.FileLog)
ans =
3×3 table
Application StartDate Size (in MB)
____________ ____________________ _____________
1. "slrt_ex_osc" 06-Nov-2024 07:29:42 2.3392
2. "slrt_ex_osc" 06-Nov-2024 07:30:06 1.3936
3. "slrt_ex_osc" 06-Nov-2024 07:30:22 1.8867
Here, the 3rd entry is still growing in size because it is being written to, so it cannot be accessed or imported.
In R2023b and later, you can now directly import the two completed file logs while recording new data (see release notes): >> import(tg.FileLog,1:2); % import the 2 completed logs while still writing to the 3rd log
In R2023a and earlier, downloading completed file logs while recording new data is not possible. The logging service must be stopped before you import data:
>> stopRecording(tg);
>> import(tg.FileLog,tg.FileLog.list); % import all 3 logs
Open SDI to see multiple separate runs for each of your experiments (you may have to check the Archive to see all runs - consider disabling SDI auto-archive for this workflow): Example 2: Connect a control signal to an Enable File Log block to implement custom logging logic
By adding an Enable File Log to your model, a new log file is created on the target every time the block is enabled. This allows you to implement custom logging logic, for example, by sending a signal of value 'true' every 30 seconds using Stateflow (see the attached model multiple_file_log_ex.slx): Alternatively, you could use a Constant block as input to the Enable File Log block and write '1' or '0' values into this parameter to start/stop the file logging. This can be done using any of the supported parameter tuning methods (SLRT Explorer, Dashboard blocks, UI components in an SLRT app, tg.setparam, etc.), or from external calibration tools like Vector CANape® or ETAS® Inca.
For MATLAB R2022a and earlier:
In R2022a and earlier, segmenting file logs during one real-time simulation run and creating separate runs in SDI is not possible for File Logs. One file log corresponds to one simulation run:
>> tg = slrealtime;
>> load(tg,'slrt_ex_osc');
% allow storing more than one log file for application before overwriting:
>> start(tg,'FileLogMaxRuns',5);
% wait for some time
>> stop(tg);
>> start(tg);
% wait for some time
>> stop(tg);
>> import(tg.FileLog,tg.FileLog.list);
In these older releases, you can use live streaming to SDI instead of file logging to achieve multiple runs without stopping the real-time simulation; however, this requires the host computer to be connected to the Speedgoat while recording at all times: