Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Semi-trivial Mathematica Question

  1. Aug 25, 2011 #1
    Hi guys,

    I have a long list of numbers which has only two values, e.g. {1,1,1,0,0,1,0,1,0,0,0...}.

    The list is ordered as a function of time -- chronologically.

    I need to see, then, how long the list stays at 1 before going to 0, and then how long the list stays at 0 before going back to 1... etc. etc. until the list terminates.

    In my example above, I would expect an output like {3,2,1,1,1,3}.

    How can I implement this?

  2. jcsd
  3. Aug 25, 2011 #2
    Woo hoo! Found my answer: the http://reference.wolfram.com/mathematica/ref/Split.html" [Broken] command.
    Last edited by a moderator: May 5, 2017
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook