Option 1: Use Root-Level Inport Data
The "From File" block was deprecated in R2020b in favor of using root-level input port data, which is a basic Simulink feature. It supports almost all Simulink data types and has richer functionality compared to the "From File" block.
The basic steps are as follows:
Step 1: Add Inport blocks to the top level of your model.
Step 2: Use the Root Inport Mapper tool, or MATLAB code, to perform the initial mapping of data to the root-level inports, as shown in the following examples:
For example, to map the variable "waveform" to a single inport, use "ExternalInput", and make sure "LoadExternalInput" is enabled. Then, build the real-time application with "slbuild":
>> load waveform.mat;
>> set_param(model,'ExternalInput','waveform');
>> set_param(model,'LoadExternalInput','on');
>> slbuild(model)
The data files are packaged in the MLDATX file at build time.
>> load waveform.mat;
>> app_object = slrealtime.Application(model);
>> updateRootLevelInportData(app_object);
This will update the data contained in the MLDATX file with the new contents of the "waveform" variable. The application must be reloaded to take effect.
Step 4: Use
Target.Stimulation objects and
reloadData to start, pause, stop, and restart the stimulation applied to root-level inports while the real-time simulation is running:
>> stop(tg.Stimulation,'all');
>> reloadData(tg.Stimulation,[1], new_waveform);
>> start(tg.Stimulation,'all');
Option 2: Use Playback block
Starting in R2022b, Playback blocks are available as another way to provide external data to applications. Other than Root-Level Inports, Playback blocks can be used at different model hierarchies to provide input data. The stimulation of the Playback block ports can be controlled and updated on target at run-time using the same Target.Stimulation objects as mentioned above. For more information, see: Load Data Using Playback Block
Option 3: Use S-functions (not recommended)
Apart from the workflows mentioned above, Simulink Real-Time does not support loading any data from files located on the target file system into the real-time application. If you wish to implement such functionality, you would have to write your own C-Code S-Function to accomplish this. Details on how to do this are ouside the scope of MathWorks Technical Support. Here are some pointers to get started: External Code Integration of Libraries and C/C++ Code with SLRT Models Note that it will not be possible to load data from .MAT files from the target using such S-functions since the MAT-file API relies on precompiled libraries that are not available for the QNX operation system.