Main Content

Configure Model to Export as FMU with Internal Variables

This topic shows how to configure a Simulink® model to export it as a Functional Mockup Unit (FMU) with internal variables. Create internal variables to observe signals that are not exposed by the input and output ports of the FMU. Doing so enables you to access internal signal values and debug your imported FMU during simulation. For more information, see Observe Internal Variables of an FMU (Simulink Test).

In a Simulink model, you can configure logged signals, test points, and datastores as internal variables of the FMU.

This workflow requires the FMU Builder for Simulink support package.

Open Model to Export as FMU with Internal Variables

This example opens a model that is to be exported as an FMU with internal variables. The model consists of a cascaded PID and a mass-spring-damper system. The reference signal specifies the desired position of the mass. The PID controller provides the force as input to the mass-spring-damper system to control the position of the mass.

Configure Logged Signals, Test Points, and Datastores as Internal Variables

  1. The model contains internal signals controlInputBusSignal, measuredOutput, and controlSignal that are not directly connected to the input or output ports. The value of the signal controlSignal is registered in datastore controlSignalStore.

  2. To mark the signal controlInputBusSignal for logging, select the signal, and on the Simulation tab, click Log Signals. For more information on signal logging, see Save Signal Data Using Signal Logging.

  3. To configure signal measuredOutput as a test point, select the signal, and on the Signal tab, click Test Point. For more information on test points, see Configure Signals as Test Points.

  4. Create a Simulink.Signal object in the base workspace for each of the signals that you want to export as an internal variable. You can create this object using the command line or the Model Explorer. For more information on creating the object, see the creation section of Simulink.Signal. The name of the object must match the name of the signal in the model. For example, in this model, the signal trackingError requires that you create the following Simulink.Signal object:

    measuredOutput = Simulink.Signal;
  5. In the Design tab of Model Explorer, set the Data type and Initial value for the object. In the Code Generation tab, set the Storage Class parameter as Exported Global.

    Signal Objects in Model Explorer

    Alternatively, modify the fields of the Simulink.Signal object at the command line. For example, for the trackingError signal, set the following.

    measuredOutput.DataType = 'double'; 
    measuredOutput.CoderInfo.StorageClass = 'ExportedGlobal'; 
    measuredOutput.InitialValue = '0';
  6. You must resolve the signals before exporting the model as an FMU. In the Modeling tab on the Simulink toolstrip, select Model Data Editor. Select the logged signals, test points, and datastores to resolve by selecting the corresponding Resolve check box. Update the model to ensure there are no conflicts.

  7. On the Simulation tab, click the drop-down button for Save. In the Export Model To section, click Standalone FMU.... Doing so opens the FMU export dialog.

  8. Click the Refresh button to compile the model. The Internal Variables tab will lists the signals that can be exported as internal variables. For each signal that you want to export as an internal variable, select the corresponding check box in the Exported column.


    Ensure that the model is configured with a fixed-step solver. Variable-step models do not support export as an FMU with internal variables.

    FMU export tab

  9. Click Create. Doing so generates the FMU with internal variables according to your specifications. You can view the internal variables of the FMU in the Output tab in the FMU block dialog box.

    FMU import tab


  • Models with a variable-step solver are not supported for export to FMU with internal variables.

  • Signals directly connected to the Inport blocks cannot be exported as internal variables.

See Also

(Simulink Test)