Documentation Home Page RT-LAB Home Page
Pour la documentation en FRANÇAIS, utilisez l'outil de traduction de votre navigateur Chrome, Edge ou Safari. Voir un exemple.

OpFromFile

Library

rtlab/Data logging

Block

The OpFromFile block reads signals from a Matlab file (.mat) and outputs a sequence of selected samples from the file.

OpFromFile block

Mask

Figure 2: OpFromFile mask.

Description

The OpFromFile block reads signals from a Matlab file (.mat) and outputs a sequence of selected samples from the file. Since all signals are read before the simulation execution, this block can be used in both real-time and non-real-time simulations.

The output sequence is defined by start and stop indexes that can be modified while the simulation is running. It is also possible to modify the output sequence using the State, Repetitive, Interpolation and Time Scaling control inputs

Parameters

Filename Mode

In static mode, the file used is the one specified in the Filename parameter. In dynamic mode, two options exist to specify which files should be read. By default, the dynamically allocated filename is composed of the Filename parameter appended with a “_” and the suffix corresponding to the File Id input value.

For example, if the name introduced in the Filename field is data.mat, the block will look for files named data_0.mat, data_1.mat, and so on. Alternatively, the filename of a comma-separated value (CSV) file containing a column with the Matlab files to be read can be entered in the Filename field.

The appropriate column is specified by appending the column number to the csv filename, separated by a comma. For example, my_matlist.csv contains Matlab filenames in column 0, requiring the Filename field to read “my_matlist.csv,0”. Files in the csv are indexed in order by row, starting from 0.

When changing the File Id, the current file is closed and a new one is opened using the new value. It should be noted that all the files opened in dynamic mode should have the same number of signals and size. If not, the size of the first opened file (Initial FileId) will be used.

File ReloadOnly used in Dynamic Filename Mode. This defines when the file is reloaded after a File Id change. In RT-LAB real-time simulation mode, it is recommended to use the "Next time model is paused" option since the "Immediate Reload" option might cause overruns. When running offline under Simulink, Immediate Reload is automatically used.
Initial File IdOnly used in Dynamic Filename Mode. Specify the default File Id to be used before the model is loaded.
FilenameName of the file that holds the data. See Filename Mode parameter for an explanation when using dynamic mode.
Real-Time PathPath where the file is located when the simulation is running on the target node.
Non-Real-Time PathPath where the file is located when the model is running on the Command Station (Running under Windows OS).
Sample TimeThe time interval between samples. Default is 0 (inherited from the model).

Inputs

StateAllow to control the execution of the current sequence (0 = STOP, 1 = RUN , 2 = PAUSE ). The behaviour of this input is similar to a CD player. A RUN command after a PAUSE will continue the current sequence (Current Index) while a RUN after a STOP will restart the sequence from the beginning (Start Index).
RepetitiveWhen set to 1 the sequence will restart once completed. When set to 0 the sequence will remain at the last value of the sequence until the next STOP or RUN command happen.
Start IndexIndex of the sample where the sequence starts. The index value must be between 0 and Max Index.
Stop IndexIndex of the sample where the sequence stops. The index value must be between 0 and Max Index.
Time Scale FactorTime scaling to be applied to the sequence. i.e. a time scaling of 2 will play the sequence 2 times slower. The value must be an integer factor or divider like 0.5 (1/2), 1, 2, 3.
InterpolationWhen set to 1, the output sequence will be linearly interpolated between file sample. This function is only useful when the file sample time is greater than the model sample time.
File idOnly used in Dynamic Filename Mode. Specify the file id to be used.

Outputs

TimeTime of the current sample (from the file time vector).
DataVector containing the current samples read from the file.
MaxIndexMaximum index that can be used for the StartIndex and StopIndex inputs. This value corresponds to the number of samples in the file, minus one.
CurIndexCurrent index of the Data.
CurFileIdOnly used in Dynamic Filename Mode. File Id of currently opened file. If input File id is outside range of acceptable files, CurFileID turns to -1.

Mat File Format

  • First row must be time values
  • The file should be saved in the V4 format

Example Script to Create a Compatible mat File

data(1,:)=0:0.001:10; %Time Array (required)
data(2,:)=5*sin(data(1,:)) %Signal 1 Data Array
data(3,:)=3*cos(data(1,:)) %Signal 2 Data Array
%Saving variable to a version 4 mat file
save my_file.mat data -V4

Example CSV File for Dynamic Filename Mode (Column 0)

data_folder/in_file_a.mat,
data_folder/in_file_b.mat,
alternative_data_folder/in_file_c.mat

Characteristics and Limitations

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.

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.

The total size of .mat files attached to all OpFromfile blocks in a model cannot exceed the RAM available in the target before loading.

This block has no special characteristics.

Direct Feedthrough

No

Discrete sample time

Yes

XHP support

No

Work offline

No

OPAL-RT TECHNOLOGIES, Inc. | 1751, rue Richardson, bureau 1060 | Montréal, Québec Canada H3K 1G6 | opal-rt.com | +1 514-935-2323
Follow OPAL-RT: LinkedIn | Facebook | YouTube | X/Twitter