๐Ÿ“„

From File

Sources
Run the live example Free ยท no sign-up ยท runs in your browser

Plays back a table of data during a simulation: a measurement from a test bench, a drive cycle, a load profile, or a signal exported from another tool. The first column is time in seconds; every further column becomes an output port, named after its header (as OpenModelica's -csvInput names inputs). Between the samples the block interpolates linearly or holds the previous sample; before the first and after the last sample it holds, extrapolates or outputs a fixed value, like the PLECS From File block.

A browser has no file paths, so the file is read once and stored in the block. It travels with the diagram: in a saved project, an export and a share link.

Mathematical Model

With rows (tk,yk)(t_k, y_k) sorted by time and tkโ‰คt<tk+1t_k \le t < t_{k+1}:

y(t)=yk+tโˆ’tktk+1โˆ’tkโ€‰(yk+1โˆ’yk)(linear),y(t)=yk(ZOH)y(t) = y_k + \frac{t - t_k}{t_{k+1} - t_k}\,(y_{k+1} - y_k) \quad \text{(linear)}, \qquad y(t) = y_k \quad \text{(ZOH)}

A time that appears twice, tk=tk+1t_k = t_{k+1}, is a discontinuity: the block outputs yk+1y_{k+1} from tkt_k on. That is how a step is written in a table.

Inputs & Outputs

Direction ID Label Type Status
← Out out1 y1 number Output

Parameters

Parameters Label Type Default Description
data Data (CSV) text 0 0; 1 1; 2 1; 3 0 Rows of time followed by the column values. Import a data file to fill it; a repeated time gives a step.
interpolation Between samples select linear
before Before the first sample select hold
beforeValue Value before the first sample number 0
after After the last sample select hold
afterValue Value after the last sample number 0

Usage Examples

Example 1: Replay a bench measurement against the model

Export the bench log as CSV with columns time;setpoint;speed. Drop it on the canvas, wire setpoint into the controller of the model and plot speed next to the simulated speed. The plot shows where model and machine part.

Example 2: A drive cycle as a load profile

A vehicle speed profile (time,speed_kmh) drives the load torque of a motor model. ZOH keeps a logged 10 Hz profile piecewise constant, as the logger saw it.

Remarks & Best Practices

  • Comparing instead of driving: to overlay a measurement on simulated signals without wiring it into the model, import the file as a reference run in the analysis panel's run rail. That gives a ghost trace and a difference plot.
  • Steps and the solver: a step in the data (a repeated time, or ZOH) is a discontinuity the variable-step solvers do not see coming. Use a fixed step or a small maximum step when the timing of a step matters.
  • File formats: CSV, MATLAB .mat (v5 to v7), Parquet and Feather/Arrow. A MAT file may hold a Simulink Structure With Time, named vectors with a time vector, or one matrix with time in the first row or column. Vectors without a time vector, or a single Parquet or Feather column, play back against their sample number: one sample per second from t = 0. A v7.3 file (HDF5) is refused: save it with save(..., '-v7').
  • Round trip: a file exported from the analysis panel or a Scope block (time column, one column per signal) loads into From File unchanged.
  • Code export: in exported C++, Python and Rust the table becomes a constant array, played back exactly as in the simulation.
  • Port names: the output labels come from the header. A file without a header gets col1, col2, โ€ฆ; the port ids stay out1, out2, โ€ฆ so wiring survives a re-import with renamed columns.

Related Components