Home > Community > FPScript > Arrays und Schleifen > Antwort auf: Arrays und Schleifen

Bernhard KantzBernhard Kantz

First you should be aware that each formula can return only one result (besides if you are using a list result).
The shortest way to solve the first issue is something like this (we assume that all datasets have the same length):

Result = TransposeMatrix({ Dataset1, Dataset2, Dataset3})

The result can than be found in Result[0], Result[1] and Result[2]. If you only need a specific index you could proceed like this:
Create a new formula called ‘DataSetFromIndex’:

Arguments Datasets, Idx
Dim MaxLen, Result

//	To simplify things we assume that all datasets have the same length
MaxLen = NumberOfRows($Datasets[0]$)

//	pre-allocate the result
Result = 0. # NumberOfRows(Datasets)

For Each Row i In Datasets Do
	Result = ($Datasets$)[Idx]


Then call it from another formula like this (for the index 1):

DatasetFromIndex({ "Dataset1", "Dataset2", "Dataset3" }, 1)

The second issue could be solved like this (assume Sig for your Signal, to avoid name clashes with the built-in function Signal):

Signal(Dataset1, Sig[0] # NumberOfRows(Dataset1))
Signal(Dataset2, Sig[1] # NumberOfRows(Dataset2))