> For the complete documentation index, see [llms.txt](https://www.opal-rt.com/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://www.opal-rt.com/docs/hypersim/model-and-simulation/import-models-from-external-software-or-code/import-from-simulink-hyperlink/export-from-simulink/use-s-functions.md).

# Use S-Functions

This page explains how S‑Functions are handled when importing Simulink models into HYPERSIM. S‑Functions allow Simulink models to execute custom code, and their behavior during import depends on how they are implemented. **In most cases, S‑Functions are imported transparently in HYPERSIM**. However, **non‑inline S‑Functions implemented as external C code require specific user actions** before importing the model into HYPERSIM.

## S‑Function types and import behavior

### Inline S‑Functions (no action required)

Inline S‑Functions are fully supported and require no special handling. This includes:

* Inline S‑Functions implemented via `.tlc` files
* MATLAB Function blocks
* Internal S‑Functions embedded in Simulink libraries
* Certain Simscape Power Systems (SPS) blocks (for example, Discrete Transport Delay)

For these cases, code generation and import into HYPERSIM are transparent to the user.

### Non‑inline S‑Functions (user action required)

Non‑inline S‑Functions are implemented as external source code and are not automatically integrated into Simulink code generation.

If the Simulink model contains a non‑inline S‑Function implemented in `.m` file, or if the S‑Function requires any MATLAB interpretation at runtime, then it **cannot** be imported to HYPERSIM.

If the Simulink model contains a non‑inline S‑Function implemented in C (`.c`), it can be imported into HYPERSIM provided that the S‑Function is compiled using `mex`. Complete the following steps before importing the model into HYPERSIM:

1. Place the `.c` file in the same directory as the Simulink model (`.slx` or `.mdl`).
2. In MATLAB, compile the S‑Function using:

```matlab
mex yourSFunction.c
```

3. Verify that the Simulink model runs correctly.
4. Import the model into HYPERSIM using the standard [Import from Simulink](https://www.opal-rt.com/docs/hypersim/model-and-simulation/import-models-from-external-software-or-code/import-from-simulink-hyperlink/import-into-hypersim.md) workflow.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://www.opal-rt.com/docs/hypersim/model-and-simulation/import-models-from-external-software-or-code/import-from-simulink-hyperlink/export-from-simulink/use-s-functions.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
