Can somebody please explain me the following:
If I try to split data every increase in 0.5:
list = Range[1.2, 3.2, 0.15]
{1.2, 1.35, 1.5, 1.65, 1.8, 1.95, 2.1, 2.25, 2.4, 2.55, 2.7, 2.85, 3., 3.15}
I would like to get the following:
{{1.2, 1.35, 1.5, 1.65}, { 1.8, 1.95, 2.1}, {2.25, 2.4, 2.55, 2.7}, {2.85,3., 3.15}
If I use the example given I here:
Splitting a list using SplitBy, by comparing adjacent elements
I can split either not at all
splittedlist = Split[list, (#1 < ( #2 - 0.1)) &]
{{1.2, 1.35, 1.5, 1.65, 1.8, 1.95, 2.1, 2.25, 2.4, 2.55, 2.7, 2.85, 3., 3.15}}
or I can split each of them
splittedlist = Split[list, (#1 < ( #2 - 0.5)) &]
{{1.2}, {1.35}, {1.5}, {1.65}, {1.8}, {1.95}, {2.1}, {2.25}, {2.4}, {2.55}, {2.7}, {2.85}, {3.}, {3.15}}
I found this package,
http : // www.theophys.kth.se/~phl/Mathematica/
which uses exactly this method (on 2D data, but still), why does it work in their method? Obviously, I am missing something.
I found this way of doing it,
Calculate mean of values in bins
but is this really the simplest way to split into intervals? I could of course write a loop, but I tried to not use a loop.
Comments
Post a Comment