I am trying to parse data output from a fluorometer. My output is basically signal intensity over time. So I have a list of 2 value lists with the first value time and the second signal e.g., {{.1,3.56},{.2,3.77},{.3,3.88}...}. The problem is after my experiment is complete (at 240 seconds), the program gives me a bunch of entries with the time increasing and absurdly high values for the signal e.g., {240.1,8000},{240.2,8000},{240.3,7999}... I have been trying to use Cases[Except[{_,8000}] to get rid of this garbage, but the number is not always 8000 and I am trying to automate this data processing to some degree. Is there a way to exclude values above say 4000? I have tried Cases[Except[{_,>4000}]] but it doesn't like the greater than in this context. I have been through the exchange, and can't find (or possibly understand) a solution. Thanks for any help you can offer!

  • $\begingroup$ Select might be an easier place to start. Similar examples are in the documentation. (One can use Select, Cases, Pick, of course, but for Cases you'll need to understand patterns a bit better.) $\endgroup$ – Michael E2 Jul 20 '16 at 19:43
  • $\begingroup$ Cases[lst, a_ /; a[[2]] < 8000]. $\endgroup$ – march Jul 20 '16 at 19:44
  • $\begingroup$ Cases[list, _?(#[[2]] < threshold &)] or Cases[list, {_, _?(# < threshold &)}] $\endgroup$ – Bob Hanlon Jul 20 '16 at 20:08

As Michael E2 said Select is an easy place to start.

Example based on the measured value less than 4000:

data = {{.1, 3.56}, {.2, 3.77}, {.3, 3.88}, {240.1, 8000}, {240.2, 8000}, {240.3, 7999}};

Select[data, #[[2]] < 4000 &]

{{0.1, 3.56}, {0.2, 3.77}, {0.3, 3.88}}

Example based on time less than 240:

Select[data, #[[1]] < 240 &]

{{0.1, 3.56}, {0.2, 3.77}, {0.3, 3.88}}

  • $\begingroup$ This is great, thanks so much! I like that method of using the slot and partition. $\endgroup$ – Rob L Jul 22 '16 at 3:11

I suppose Pick will help as well.

For example:

Pick[list, UnitStep[list[[;;,1]]-240],0]

Pick[list, UnitStep[list[[;;,2]]-4000],0]

The basic idea is to generate another list including information you want from the original list, then select using some criteria apply to the new list.

Thus, this method is wider applicable: Simple select can be done easily by Unit**** functions and you can select by the property of previous elements or latter elements from the same list via RotateLeft or ListCorrelate. Also, you may use another list as selection criteria.

Also, this will be faster when dealing with purely numerical lists, like your situation.

Hope this can help you


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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