Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
1995
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 1995

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Help with lists

  • To: mathgroup at smc.vnet.net
  • Subject: [mg2809] Re: [mg2782] Help with lists
  • From: brucec (Bruce Carpenter)
  • Date: Tue, 19 Dec 1995 02:41:12 -0500

>        Hi! I'm having problems with the lists I try and manipulate.
>I set a list as something and then try and get mathematica to pull out a
>number in a range and it doesn't return anything. Like so;
>
>In[1]:  list = {-5,-4,-3,-2,-1,0,1,2,3,4,5}
>In[2]:  Count[list,{-2,2}]
>
>What I'm trying to get the program to do is Count the values in the list
>between certain values. I need to be able to do this over a negative and
>positive domain. Could someone let me know how to do this, or perhaps a
>way to get around the limitations of the program?
>Thanks
>Andre

You could use the built-in Interval arithmetic along with the pattern
matching construct of Cases(or Count, for that matter):

In[25]:=
??Interval*
Interval             IntervalMemberQ      IntervalUnion
IntervalIntersection
In[26]:=
mylist = {-5,-4,-3,-2,-1,0,1,2,3,4,5};
Cases[list,a_/;IntervalMemberQ[Interval[{-2,2}],a]]
Out[27]=
{-2, -1, 0, 1, 2}
In[28]:=
Count[list,a_/;IntervalMemberQ[Interval[{-2,2}],a]]
Out[28]=
5

Cheers,
Bruce Carpenter




  • Prev by Date: Re: Re: Oh why is life never easy? Need help with |vector|
  • Next by Date: noise
  • Previous by thread: Re: Help with lists
  • Next by thread: Re; Problem with Packages