2
$\begingroup$

I am new to Mathematica and would appreciate any help.

I'd like to partition my data which is comprised of {time x analog input} into sublists of consecutive time. In other words, my data looks like this:

{1, 3.567}, {2, 3.768}, {3, 4.214}, {15,3.986}, {16,3.785}, {28,2.998}, {29,3.678}, {30,3.216}, {31,4.012} etc.

And what I'd like is to be able to group them into:

{{1, 3.567}, {2, 3.768}, {3, 4.214}}, {{15,3.986}, {16,3.785}}, {{28,2.998}, {29,3.678}, {30,3.216}, {31,4.012}} etc.

How can I make a function where the sub-list varies depending on whether the first part of each data point, i.e. time, is directly after the other, and split it if the difference between the value and the value prior to it is greater than 1?

$\endgroup$
0

1 Answer 1

3
$\begingroup$

This

f[{t1_, a1_}, {t2_, a2_}] := t2-t1 ==1;
Split[{{1,3.567}, {2,3.768}, {3,4.214}, {15 3.986}, {16,3.785},
       {28, 2.998}, {29, 3.678}, {30, 3.216}, {31, 4.012}}, f]

returns this

(* {{{1, 3.567}, {2, 3.768}, {3, 4.214}},
   {{15, 3.986}, {16, 3.785}},
   {{28, 2.998}, {29, 3.678}, {30, 3.216}, {31, 4.012}}} *)
$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.