> 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/rt-lab/simulink-blocks-reference/rt-lab-library/opfromfile.md).

# OpFromFile

## Description

<figure><img src="https://96827845-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNRdpSk8kjn20gXAexnt6%2Fuploads%2Fgit-blob-7fad72a32140f0225f6623e4c8b7c83483449848%2FRTL_opfromfile_block.png?alt=media" alt=""><figcaption></figcaption></figure>

The **OpFromFile** block, located in the **RT-LAB/Data logging** library, reads signals from a Matlab (.mat) file and outputs a sequence of selected samples from the file. All signals are loaded before the simulation starts, so the block works in both real-time and non-real-time simulations. Normally, all files should contain the same number of signals; but it is not necessary. If the number of signals is different between two files, the output width will stay the same than the file used during compilation.

{% hint style="danger" %}
The total size of .mat files attached to all OpFromfile blocks in a model cannot exceed the RAM available in the simulator before loading.
{% endhint %}

**There are two cases:**

* If the number of signals in the new file is inferior to the number of signals in the first file: in this case, all of the signals missing will be replaced with the previously saved signals.
* If the number of signals in the new files is superior to the number of signals in the first file: in this case, all of the signals in addition will be ignored and will not be outputted.

You can define the output sequence using start and stop indexes and adjust it during execution with the State, Repetitive, Interpolation, and Time Scale Factor inputs.

{% hint style="info" %}
Mat file format: the first row must contain time values, and the file must be saved in Matlab V4 format.
{% endhint %}

## Mask parameters

<figure><img src="https://96827845-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNRdpSk8kjn20gXAexnt6%2Fuploads%2Fgit-blob-69d1161a547fe2409f72b479f4e4fef5e6d43314%2FRTL_opfromfile_mask.png?alt=media" alt="" width="329"><figcaption></figcaption></figure>

<table><thead><tr><th width="221.79998779296875">Parameter</th><th>Description</th></tr></thead><tbody><tr><td><strong>Filename Mode</strong></td><td><p><strong>Static mode</strong> uses the file specified in Filename.</p><p><strong>Dynamic mode</strong> offers two options to select files. By default, the dynamically selected filename is the Filename value appended with an underscore and the File Id input value.</p><p>Example: if Filename is data.mat, the block looks for data_0.mat, data_1.mat, and so on.</p><p>Alternatively, enter the name of a comma-separated value (CSV) file that lists Matlab files. Specify the column by appending its index to the CSV filename, separated by a comma.</p><p>Example: if my_matlist.csv lists Matlab filenames in column 0, set Filename to "my_matlist.csv,0". Files in the CSV are indexed by row starting at 0. When File Id changes, the current file closes and a new one opens using the new value. All files used in dynamic mode should have the same number of signals and the same size; otherwise, the size of the first opened file (Initial File Id) is used.</p></td></tr><tr><td><strong>File Reload</strong></td><td><p>Used only in Dynamic Filename Mode.</p><p>Defines when to reload the file after a File Id change. In RT-LAB real-time simulation mode, use "Next time model is paused" to avoid overruns; "Immediate Reload" may cause overruns. When running offline under Simulink, Immediate Reload is used automatically.</p></td></tr><tr><td><strong>Initial File Id</strong></td><td>Used only in Dynamic Filename Mode. Default File Id used before the model is loaded.</td></tr><tr><td><strong>Filename</strong></td><td>Name of the data file. See Filename Mode for details when using dynamic mode.</td></tr><tr><td><strong>Real-Time Path</strong></td><td>Path to the file when the simulation runs on the simulator.</td></tr><tr><td><strong>Non-Real-Time Path</strong></td><td>Path to the file when the model runs on the workstation (Windows).</td></tr><tr><td><strong>Sample Time</strong></td><td>Time interval between samples. Default: 0 (inherited from the model).</td></tr></tbody></table>

## Inputs

<table><thead><tr><th width="221">Input</th><th>Description</th></tr></thead><tbody><tr><td><strong>State</strong></td><td>Controls the sequence execution (0 = STOP, 1 = RUN, 2 = PAUSE). RUN after PAUSE continues from the current index; RUN after STOP restarts at Start Index.</td></tr><tr><td><strong>Repetitive</strong></td><td>When 1, the sequence restarts after completion. When 0, the sequence holds its last value until the next STOP or RUN command.</td></tr><tr><td><strong>Start Index</strong></td><td>Index of the first sample. Must be between 0 and MaxIndex.</td></tr><tr><td><strong>Stop Index</strong></td><td>Index of the last sample. Must be between 0 and MaxIndex.</td></tr><tr><td><strong>Time Scale Factor</strong></td><td>Time scaling applied to the sequence. For example, 2 plays the sequence twice as slowly. Use integer factors or dividers such as 0.5 (1/2), 1, 2, 3.</td></tr><tr><td><strong>Interpolation</strong></td><td>When 1, applies linear interpolation between file samples. Useful when the file sample time is greater than the model sample time.</td></tr><tr><td><strong>File id</strong></td><td>Used only in Dynamic Filename Mode. File id to use.</td></tr></tbody></table>

## Outputs

<table><thead><tr><th width="221.00006103515625">Output</th><th>Description</th></tr></thead><tbody><tr><td><strong>Time</strong></td><td>Time of the current sample from the file time vector.</td></tr><tr><td><strong>Data</strong></td><td>Vector containing the current samples read from the file.</td></tr><tr><td><strong>MaxIndex</strong></td><td>Maximum valid index for Start Index and Stop Index (number of samples in the file minus one).</td></tr><tr><td><strong>CurIndex</strong></td><td>Current data index.</td></tr><tr><td><strong>CurFileId</strong></td><td>Used only in Dynamic Filename Mode. File Id of the currently opened file. If the input File id is outside the valid range, CurFileID becomes -1.</td></tr></tbody></table>

## Characteristics and limitations

<table><thead><tr><th width="221">Characteristic</th><th>Value</th></tr></thead><tbody><tr><td>Direct Feedthrough</td><td>No</td></tr><tr><td>Discrete sample time</td><td>Yes</td></tr><tr><td>XHP support</td><td>No</td></tr><tr><td>Work offline</td><td>No</td></tr></tbody></table>


---

# 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/rt-lab/simulink-blocks-reference/rt-lab-library/opfromfile.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.
