File Logging Basics: Using File Log blocks to log signal data on a Speedgoat target with Simulink Real-Time R2020b and later

47 views (last 30 days)
The File Scope block and the "simulinkrealtime.filescope" object are no longer available in Simulink Real-Time (SLRT) R2020b and beyond. How can I perform signal data logging to my Speedgoat target computer file system in R2020b and beyond?

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 30 Jul 2025
Edited: MathWorks Support Team on 30 Jul 2025
To write real-time signal data to a local file on your Speedgoat target computer's SSD, use the File Log block from R2020b onwards. File logging is a lossless and robust method to record many signals at very high data rates. All signals are recorded in one single log file on the target. The data is logged when no host computer is connected, making it ideal for standalone use. The logged data can be imported into MATLAB and viewed after Simulink Real-Time stops writing to it.
To get started with file logs, see the following documentation pages: 
This article covers the various stages of using file logs with Simulink Real-Time:

Prepare model for file logging

Connect all signals that you would like to record to File Log blocks. Adding new signals to file logging after compiling the application is not possible. File Log blocks support common signal types, including array and bus signals.
To enable and disable the file logging recording service using a control signal, connect an Enable File Log block to it. It is also possible to enclose File Log blocks in Enabled Subsystems to exclude certain signals from logging. Other conditional block execution semantics like for-iterator, function-call, or triggered subsystem are also supported.
Each File Log block has a 'Decimation' parameter to reduce samples without changing the signal rate. The decimation can be changed for every simulation run by using File Log decimation functions (R2022a+).
Note that file log data can only be imported into MATLAB and viewed after the recording run has stopped. Signals that require live streaming and monitoring should be configured with logging badges. Live-streaming and logging a signal simultaneously, even at different rates, is possible. See: How can I stream signals from Speedgoat hardware to Simulation Data Inspector (SDI)?
.

Start and stop logging during simulation

Each real-time application run generates a log file on the target computer. By default, only one log file is stored at a time and overwrites the previous one. To store multiple runs, increase the number of stored logs as explained here: How can I control the number of file logs stored on my Speedgoat target machine?
Since R2022b, you can create multiple log files during a single real-time simulation using either the interactive Start/Stop Recording API, or an 'Enable File Log' block in your model. For more details and example code, see: How can I do intermittent logging with real-time File Log blocks to generate multiple log files and SDI runs?

Import file logs to host computer

There are different ways to import completed file log runs to the host computer:
• Automatic file log import (default): If the MATLAB host computer is connected during the run, file logs are automatically transferred at the end of the run. This behavior is enabled by default.
• Interactive file log import: If the host computer is not connected when the run stops, or the 'AutoImportFileLog' option is disabled, you can import file logs manually using one of the following options:
  1. MATLAB API: Use the tg.FileLog.import command in a script or directly from the MATLAB Command Window.
  2. 'Import File Log' dialog: Open the dialog by pressing the corresponding button in SLRT Explorer, in the Real-Time tab of your model, or in your custom SLRT app via an ImportFileLogButton (R2023b+). You can also use the openImportDialog command to launch the dialog programmatically.
• Manual file log import (without MATLAB): Since R2021a, there is a supported workflow to copy file log data from the Speedgoat target computer to a host computer without MATLAB. See the following answer for details: How can I transfer file log data from my Speedgoat target to a host computer without MATLAB?
• Deployed SLRT apps: Some limitations exist when using file logs with deployed SLRT apps. For more information, see: Can I import and view File Log data from my Speedgoat target when using a MATLAB Compiler deployed SLRT app?
.

View, store, and post-process logged data

    Imported file log runs automatically load to the Simulation Data Inspector (SDI). In addition, the data is saved to the 'logsout' variable in the MATLAB base workspace, unless the 'ExportToBaseWorkspace' option is disabled.
    You can export the logged data to a MAT or XLSX file, or to variables in the workspace. Save the whole SDI session, including the configured view, as an MLDATX file. For a full overview of SDI export capabilities, see Save and Share Simulation Data Inspector Data and Views.
    An example with different post-processing code samples can be found here: Parameter Tuning and Data Logging.
    ⚠️ Data loss warning: In MATLAB R2020b through R2022a, File log runs are deleted from the target SSD after transfer to the host computer. This means that you must save the data from SDI or the base workspace before closing MATLAB. If you close MATLAB without saving the data, your logged data is lost. We recommend upgrading to R2022b and later, where auto-deletion of imported file logs does not occur. 

    More Answers (0)

    Community Treasure Hunt

    Find the treasures in MATLAB Central and discover how the community can help you!

    Start Hunting!