Building Data Structures

23.08.2021

FPScript provides operators and functions to help you build your own data structures.

Linear Data Series

For instance, this Data Series operator creates a data series with ascending values:

(100, 0., 1.)

100 is the number of values, 0. is the starting value, and 1. is the increment. If you prefer to specify the starting value, the end value and the sampling interval, use the Series Function:

Series(0, 100, 1)

generates a data series with 101 values with a starting value of 0, end value of 100 and sampling interval of 1. Here, the data type is always a 64-bit floating point value.

If you use quantities, you can specify different units, but they must be compatible:

(2000, 0 s, 1 ms) or Series(0 s, 2 s, 1 ms)

The result contains the unit that is furthest to the left and thus is equal to:

(2000, 0 s, 0.001 s)

Data Series and Matrices with Constant Content

The Multiply operator is used to create data series or data matrices with constant content:

1.5 # 100n

The above example shows a data series with 100 times the value of 1.5. The scalar value 1.5 has been multiplied 100 times.

1.5 # 100n # 20n  generates a two-dimensional data matrix with 20 data series of 100 values each.

TRUE # Shape(Matrix)        generates a matrix of Boolean values whose number of columns and rows corresponds to an existing matrix.

Even here you can multiply quantities:

1.5 N m # 100n

Data Series and Matrices with Variable Content

You can also bundle different scalar values into data series and data series into data matrices:

{ 1.5, 2.6, 7.8 }

The Bundle operator bundles the scalar values into a data series with three values. The length of the list is not restricted. Of course, in addition to constant scalar values, you can write arithmetical expressions that return scalar values.

{ DataSeries1, DataSeries2, DataSeries3 }  bundles three one-dimensional data series into one two-dimensional data matrix. The data series should be the same length.

All elements of a data series or data matrix are of the same data type. This does not apply to components of aggregate data structures; for instance, the X component of a signal can have a different data type than the Y component.

Instead of numeric values, you can also bundle quantities. It is sufficient to specify a unit for the first value; this will then apply to the other values.

{ 1.5 kg, 2.6, 7.8 }

If you specify different units, they must be compatible. The result contains the unit of the first quantity:

{ 50 mV, 0.5 V, -0.7 V } corresponds to the input of { 50 mV, 500 mV, -700 mV }.

Lists with Multiple Independent Elements

The List operator brings together several values or quantities that, for their part, can have any data structures and data types. Each element of a list has the option of having a name. Since each list element can in turn also be a list, any deeply nested structures can be built.

[ <Solution> Data Series, <ChiSquare> Scalar Value ]  compiles the solution vector from a curve fitting and the goodness-of-fit measure into a list. The names provided in angle brackets are optional and describe the list elements.

To create a list of objects easily, you can use the placeholders '*' and '?' in the path name. For example:

'\Measurement*\Signal'        corresponds to [\Measurement1\Signal, \Measurement2\Signal, ...].

Use the '*' placeholder for a string of any length and the '?' placeholder for a single character.

Note:  The use of list element names is no longer recommended in FlexPro version 10 and higher. Instead, use the AssignHeader function to assign header information to the list elements.

Lists are used for multichannel analyses or when a single calculation produces several independent results that cannot be calculated separately.

To access a list element, you can use its name, if available, or the position of the element in the list:

List.ChiSquare  accesses the second element in the list above.

List.[1n]         gives you the same result without using the name of the element.

You can use the ListToSeries function to convert a list with items of the same structure into a data series, data matrix or signal series.

Constructing Aggregate Data Structures

You can use the Signal function to create signal, signal series and space curve aggregate data structures from the basic data series and data matrix data structures:

Signal(Amplitude, Time) joins two data series with measurement values and the corresponding time values to form a signal. Amplitude and Time are then the components of the signal.

Concatenating Data

The Concatenation operator appends data sets to each other:

DataSeries1 : DataSeries2

You can also append signals to each other. In this case, the X component of the second signal is shifted automatically so that it follows seamlessly after the first.

If you concatenate quantities, the unit of the argument on the right is adjusted to the one on the left.

Share article or send as email:

You might be interested in these articles