Main Content

Configure Model to Log Signals on SD Card

You need to enable the settings required for MAT-file logging by following these steps:

  1. In the Simulink window, go to Modeling > Model Settings to open the Configuration Parameters dialog box.

  2. In the Code Generation pane, go to Interface > Advanced Parameters, and select MAT-file logging.

SD card logging is supported in models containing To Workspace block. You must specify the values for several block parameters in the To Workspace block, as described in this section.

To configure a Simulink® model to run on the target hardware, perform these steps:

  1. On the Modeling tab, in the Simulate section, set the Stop Time. The signals are logged for the time period specified in the Stop Time parameter. The default value is Inf. Enter time in seconds to log signals for that time period.

  2. In the Simulink model, set the parameter values of To Workspace blocks.

Settings for To Workspace Block

Double-click the To Workspace block, and specify these parameters in the Block Parameter dialog box.

Variable name

Specify a variable name for the logged data.

Limit data points to last

You can use the default value for this parameter.


Before you simulate the model, you need to run the px4PrepareModelForMATFileLogging() function in MATLAB. This function optimizes the value for Limit data points to last. For details, see Prepare Model for Simulation and Deployment.


Use this parameter for the block to write data points at every nth sample, where n is the decimation factor. The default decimation, 1, writes data at every time sample.

For example, if you specify Decimation as 5, the block writes data at every fifth sample. For example, if the block sample time is 0.1 and Decimation is 5, the data points at 0, 0.5, 1, 1.5, ... seconds are logged. The data points are logged until the Simulation stop time is reached.

Save format

Select a format of the variable to which you save data. SD card logging supports only these three formats: Array, Structure with Time, or Structure.

  • Array: Save data as an array with associated time information. This format does not support variable-size data.

  • Structure with Time: Save data as a structure with associated time information.

  • Structure: Save data as a structure.


Select Save format as Array to use the memory efficiently.

Sample time (–1 for inherited)

Specify an interval at which the block reads data. When you specify this parameter as –1, the sample time is inherited from the driving block.

Related Topics