Combine#
Combines up to four data inputs with a user-defined Python expression and stores the result.
Description#
The test reads up to four data inputs (data1 to data4) and evaluates a user-defined Python expression that combines them.
Each data input can be a string, a float, a boolean or a float array (e.g. when bound to a variable).
If a data input is a string, it is evaluated as a Python expression first, so literals like 5.0, True, [1, 2, 3] or expressions like 2**10 can be entered directly.
The resolved values are stored as output parameters Data1 to Data4 using the store method that matches their type (float, boolean, string or float array). For array inputs, an additional index array (Index1 to Index4) is stored that can be used as X axis in diagrams.
The resolved values are then available as variables data1 to data4 in the Python expression.
The expression must assign the combined value to the variable result (initialized to 0), which is stored as output parameter Expression.
The numpy package is available as np in both the data inputs and the expression.
Empty data inputs are skipped.
Input parameters#
| Parameter | Description |
|---|---|
| data1 ... data4 | The data inputs to combine. Each can be a string, float, boolean or float array. Strings are evaluated as Python expressions (e.g. [1, 2, 3]). |
| Python expression | Python code that combines the data inputs. The inputs are available as data1 to data4 and the result must be assigned to the variable result. |
Output parameters#
| Parameter | Description |
|---|---|
| Data1 ... Data4 | The resolved value of each data input, stored as float, boolean, string or float array depending on its type. |
| Index1 ... Index4 | The index array (0 to N-1) of the corresponding data input. Only stored if the data input is an array. |
| Expression | The value of the variable result after the Python expression has been executed. |
Supported devices#
This test does not require any device.
Example#
Goal:
Calculating the element-wise sum of two arrays.
Measmatic setup:
- Add a new Combine test to the test sequence by dragging and dropping a Combine test from the test picker into the test sequence.
- Enter
[1, 2, 3]into the data1 input and[4, 5, 6]into the data2 input. - Enter
result = np.add(data1, data2)into the Python expression input. - Execute the test in Measmatic by pressing the run all tests or run single test (when the Combine test is selected) button.
The output parameter Expression contains the array
[5, 7, 9], and Data1/Data2 contain the two input arrays.
See also: