# What is the equivalent of MATLAB's “timealign” function?

What is the equivalent of MATLAB's "timealign" function?

Given two sequences (lists of values) and offsets, timealign will insert 0's into sequences to align them so they have the same number of elements and are thus aligned for the purpose of doing operations across both sequences in parallel.

-

Assuming it's this timealign

Here's a way to do it using rules, the input is slightly altered and now takes {t1, u1}, {t2, u2}, ... as input instead of t1, t2, u1, u2. Null is used instead of NaN, the time indices don't have to be ordered but will be in the result:

timeAlign[pairs_List] :=
With[{
t = Union @@ pairs[[All, 1]]
},
Prepend[
Replace[t,
Append[
Thread[First@# -> Last@#], _ -> Null
]&/@pairs,
{1}],
t]
]
timeAlign[pairs__List] := timeAlign[{pairs}]

timeAlign[
{{3, 2, 1}, {8, 7, 6}},
{{2, 4, 5}, {{3, 4}, {-1, 2}, {9, 12}}},
{{1, 5, 8}, {a, b, c}}
] // TeXForm


$$\left( \begin{array}{cccccc} 1 & 2 & 3 & 4 & 5 & 8 \\ 6 & 7 & 8 & \text{Null} & \text{Null} & \text{Null} \\ \text{Null} & \{3,4\} & \text{Null} & \{-1,2\} & \{9,12\} & \text{Null} \\ a & \text{Null} & \text{Null} & \text{Null} & b & c \\ \end{array} \right)$$

-
I guess I will "accept" this as an answer, if by this complicated formula you mean to say that Mathematica has no equivalent of timealign unless you program it yourself. – Tyler Durden Oct 29 '13 at 16:39