data

Navigation:  Language Reference > Functions > External >

data

Previous pageReturn to chapter overviewNext page

Syntax

y = data(filename,column);

Description

This function generates an output by linear interpolation of data read from file. The data on file is stored in columns. The first column contains the time values (t) and the second column contains the corresponding output values (y).

The time data of the first column needs to be monotonically increasing.
Discontinuities are allowed, by providing the same time point twice in the table.
Values outside of the range, are computed by linear extrapolation of the last two points.

 

The first argument (filename) of this function must be a parameter of the type string and is used as a reference to a filename. This reference can be specified using the complete path or relative to the model directory. The second argument (column) of this function must be a parameter of the type integer denoting a whole number. It is used to denote the column number.

 

table

 

0

0.5

2.5

3.5

4.5

5.5

7

8

(example):

 

-0.5

-1

-1

0

1

1.75

2.5

2.5

data

 

The input file must be an ASCII (text) file or a Comma Separated Values (.csv) file and should consist at least two columns of data. The first column (number 0) should always contain the time values. The other columns (number 1, 2, 3, etc.) should contain the corresponding data values. The parameter column is used to specify which column is used for as output data.

 

 

The various values must be separated by a space, a tab or a comma. Each new set of time and data values must start on a new line. No comment or other text may be part of the file. The filename of the input file can be specified using the complete path (e.g. c:\data\data.tbl). When no path is given, the file is assumed to be in the same directory as your model.

 

The first row may contain names for the columns. Names should be indicated by quotation marks (").

Example

parameters

 string filename = 'data.txt';

 integer col = 2;

variables

 real y;

equations

 y = data(filename,col);

 

Example data.txt file with header:

 

"time","x","y"

0.0, 1, 2

0.1, 5, 10

0.2, 6, 11

 
Limitations

y must be a scalar. from_file must be string parameter. x must be an integer parameter.