Option 1: Use Root-Level Inport Data
The "From File" block was deprecated in R2020b in favor of using the root-level input port data 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 Inports 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". Make sure the "LoadExternalInput" option 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 input data files are packaged in the MLDATX file at build time. Unless you explicitly stop stimulation before start, the input data will be applied from T=0 every time you start the real-time simulation.
>> 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. Unless you explicitly stop stimulation before start, the new input data will be applied from T=0 every time you start the real-time simulation.
Step 4: Use
Target.Stimulation objects (R2021a+) and
reloadData to start, pause, stop, and restart the stimulation applied to root-level inports at any point T=x 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)