Skip to main content

Matlab Simulink

Note: Users must procure and maintain valid licenses to integrate this commercial DE tool with the Istari Digital platform. Please contact your local IT administrator for assistance.

Supported Functions:

extract
run

Getting Started

The Simulink integration provides support for MATLAB SIMULINK, allowing users to extract data from and run MATLAB SIMULINK simulations.

Upload: Yes

Files Supported

The Istari DigitalPlatform can extract from the following file types: .slx

Other SIMULINK simulation file types not supported at this time. Please submit a feature request if an important file type is not supported.

Example Files

Download Example Simulation: example_simulation.slx

Setup for Administrators

Ensure that MATLAB and SIMULINK are installed on a machine with Istari Digital Agent and appropriate Istari Digital Software. Verify that the installation is up to date with the latest patches and updates from MATLAB.

Version Compatibility

The Simulink software can produce a number of artifacts extracted from the SIMULINK model. The table below describes each output artifact and its type.

Function Coverage and Outputs

The SIMULINK software can produce a number of artifacts extracted from the SIMULINK model. The table below describes each output artifact and its type.

RouteCoverageArtifact Content Example
Extract global model image - PNGYes
Extract input block parameters - JSONYes
Extract global model parameters - JSONYes
Extract workspace variables - JSONYes
Extract subsystems - JSONYes
Extract non-time varying results - JSONYes
Extract time varying results - CSVYes
Extract scope figures - PNGYes
Extract errors and warnings - JSONYes

Multiple Input File Support

The module supports executing a MATLAB .m initialization script before running the simulation through the SDK. This script allows for workspace population, setting up necessary variables, and ensuring a controlled simulation environment.

Specifying Stop-Time

When running a simulation, users can specify a stop-time to control the simulation duration. This ensures more granular control over simulation execution. If no value is passed, the value set in the model is used. If that value is infinity, then a default value of 10 seconds is used.

Tips and tricks for model extraction and Reuse

This section will guide users through creating a Simulink model for optimal interaction with the provided software (SDK/platform). Some artifacts supported for extraction from the Simulink model requires specific steps.

Defining Model Workspace Variables

Model Workspace Variables are essential for setting simulation parameters that are independent of MATLAB's Base Workspace. These variables must be created prior to running the simulation.

Steps:

  1. Open the Simulink Model:

    • Open your .slx file in Simulink.
  2. Open the Model Explorer:

    • Navigate to the Modeling tab and click on Model Explorer.
    • Alternatively, use the keyboard shortcut Ctrl + H or go to View > Model Explorer.
  3. Select the Model Workspace:

    • In the Model Explorer, locate your model in the hierarchical list on the left, and select Model Workspace under the model name.
  4. Create a Variable:

    • In the top pane, right-click and select Add > Variable.
    • Specify the Name, Value, and Data Type for the variable.
    • You can define arrays, structures, or more complex data types if needed.
  5. Save the Model:

    • Click Apply and OK to save the changes. The variables are now defined in the Model Workspace and are ready for use by the blocks in your model and for extraction.
Figure 1: Defining Model Workspace Variables

Modifying the Model to Log Selected Signals

To log signals in a Simulink model, follow these steps to configure the signals appropriately:

Steps:

  1. Open the Simulink Model:

    • Open your .slx file in Simulink.
  2. Navigate to Signal Logging Settings:

    • Go to the Modeling tab and select Model Settings.
    • In the Configuration Parameters window, navigate to the Data Import/Export section.
  3. Ensure Default Settings for Data Import/Export:

    • In the Data Import/Export section, make sure these items are ticked:
      • Time
      • States
      • Output
      • Signal Logging
      • Data Stores
    • This configuration ensures that the simulation outputs are correctly saved to the workspace and can be utilized by the run function.
      1. Save and Apply Changes:
    • Click Apply and then OK to save the changes and close the Configuration Parameters window.
      Figure 2: Maintain the Default Values for Data Import/Export Settings
  4. Select Signals for Logging:

    • In the Signal Logging Selector window, you can choose specific signals by clicking on the checkboxes next to each signal name.
    • If you need to log a time-varying signal, ensure it is connected to a source that changes over time, such as a Sine Wave or Signal Builder block.
    • For non-time-varying signals, connect it to a constant source, such as a Constant or Gain block.
  5. Verify Signal Logging Configuration:

    • Ensure that the selected signals are marked with a logging indicator (a blue symbol or highlighted in blue) in the model to confirm successful configuration.
Figure 3: Selecting Signals for Logging in Simulink

Detailed SDK Reference

Prerequisite: Install Istari Digital SDK and initialize Istari Digital Client per instructions here

Step 1: Upload, Extract, and Run the File(s)

Upload the file as a model

slx_model = client.add_model(
path="simulation.slx",
description="Simulink example model",
display_name="Simulink model name",
)

matlab_script = client.add_model(
path="script.m",
description="Matab example script",
display_name="Script name",
)

print(f"SLX file uploaded as model {slx_model.id}")
print(f"M file uploaded as model {matlab_script.id}")
extraction_job = client.add_job(
model_id = slx_model.id,
function = "@istari:extract",
tool_name = "matlab",
tool_version = "R2023b",
operating_system = "Ubuntu 20.04",
)
print(f"Extraction started for model ID {model.id}, job ID: {extraction_job.id}")
m_source = NewSource(revision_id=matlab_script.revision.id, relationship_identifier="script")

run_simulation_job: Job = client.add_job(
model_id= slx_model.id,
function="@istari:run_simulink",
tool_name="matlab",
operating_system="Windows 10",
parameters= {"stop_time": 60},
sources=[m_source]
)

print(f"Created job {run_simulation_job.id}")
print(f" > Model ID: {run_simulation_job.model.id}")
print(f" > Function: {run_simulation_job.function.name}")
print(f" > Tool Name: {run_simulation_job.function.tool_name}")
print(f" > Tool Version: {run_simulation_job.function.tool_versions[0].tool_version}")
print(f" > Operating System: {run_simulation_job.function.operating_systems[0].name}")

Please choose appropriate tool_name, tool_version, and operating_system for your installation of this software.
Above is an example of how to call the function

Step 2: Check the Job Status

extraction_job.poll_job()

Step 3: Retrieve Results

Example

for artifact in slx_model.artifacts:
output_file_path = f"c:\\extracts\\{artifact.name}"

if artifact.extension in ["txt", "csv", "md", "json", "html"]:
with open(output_file_path, "w") as f:
f.write(artifact.read_text())
else:
with open(output_file_path, "wb") as f:
f.write(artifact.read_bytes())

Troubleshooting

  1. For general Agent and Software Troubleshooting Click Here

  2. Missing Artifacts:

    If certain artifacts or part(s) of an artifact are missing after extraction (e.g., workspace_variables.json, non_time_varying_signals.json, or scope_figures), this typically indicates that the Simulink model is not fully configured according to the optimal standards.

    Suggested Action:

  3. Incorrect or Missing Workspace Variables:

    • If the parameter values in the extracted files do not match the expected results, check if the model’s Model Workspace and Base Workspace have conflicting variable names. Rename the conflicting variables and try running the extraction again.
  4. Simulation Failures During run:

    • Ensure that the simulation’s start and stop times are appropriate for the model being used.
    • If the simulation fails, recheck the model’s configuration to ensure there are no missing signals or incorrectly configured scopes. Any error messages causing the run to fail are likely outlined in the error_warnings.txt file produced by the extract function.

For more information, please refer to the Tips and tricks for model extraction and Reuse or contact the Istari Digital support team.

FAQ