Extracting Data

23.08.2021

In addition to calculating data and creating data structures, extracting parts of data sets is an important use of FPScript; for instance, all local maxima in a signal or the range between two zero crossings. For these types of applications, FPScript offers two very powerful index operators.

Index Operator

The Index Operator extracts individual values or ranges of values using their position in the data structure. All rows in data series and all rows and columns in data matrices are numbered starting with zero. Negative indices are counted from the end, which means that -1 indexes the last row or column. The index operation makes it possible for you to access individual values or ranges using these numbers.

DataSeries[99n]     reads, for instance, the hundredth value from a data series.

DataSeries[-2n]     reads the second to the last value from the data series.

DataSeries[0n, 49n]     creates a data series with the first 50 values from DataSeries.

DataSeries[49n, -1n]     creates a range from the 50th value to the last value of a data series.

DataSeries[{0n, 5n, 7n, 9n}]     creates a data series with the values that have indices listed. Here, the Bundle operator was used to bring together the required indices into a data series.

DataSeries[(NumberOfRows(DataSeries), NumberOfRows(DataSeries) - 1n, -1n)]

Here, the data series operator is used to generate the indices. The statement reverses the order of values in the data series.

For a data matrix, specify two indices. The first index selects one or more columns and the second selects one or more rows:

DataMatrix[1n][2n]     reads, for instance, the third value from the second column of the data matrix as a scalar value.

DataMatrix[-1n]     reads the last column from a data matrix as data series.

DataMatrix[][2n]     reads the third row from a data matrix as a data series.

Alternatively, you can use a 2D Index. This is a data matrix with two rows and n columns. Each column contains the column and row index of a value to be extracted:

DataMatrix[{ {1, 0}, {0, 1} }]    takes two values from a data matrix as a data series. Corresponds to {  DataMatrix[1][0], DataMatrix[0][1] }.

Value Index Operator

When working with signals and signal series, it often makes more sense to specify the X and Z values directly when indexing sections rather to work with the indices. To do this, FPScript provides the Value Index Operator .

Signal[[0 s, 4.5 s]]    creates, for example, a partial signal with the points of the first 4.5 seconds.

Note that the operation functions as expected even when the X component of the signal has the unit ms, for instance.

SignalSeries[[3.5 kHz]]    extracts the signal with the Z value 3.5 kHz from the signal series.

The syntax of the Value Index operator corresponds to that of the Index operator. All you have to do is to include all square brackets twice. FPScript then interprets the indices specified as X or Z values and looks for these in the X or Z component of the signal or signal series in order to obtain the positions.

List Element Operator

You can use the List Element Operator to extract one or more elements from a list, allowing you to work with the list element indices or names.

List.[1n]   provides, for instance, the second element in the list.

List.[-2n]   takes the second to last element from a list.

List.[1, 2]   returns a partial list with the 2nd and 3rd element.

List.Name   takes the primary element called "Name" from a list.

List.["Current*"]   returns all list elements whose names start with "Current".

Note: Please be aware that accessing list items by their names is not always clear, since in a list many items could share the same name.

Share article or send as email:

You might be interested in these articles