Re: Mathematica 6.0 easier for me ... (small review)
- To: mathgroup at smc.vnet.net
- Subject: [mg76586] Re: [mg76457] Mathematica 6.0 easier for me ... (small review)
- From: János <janos.lobb at yale.edu>
- Date: Thu, 24 May 2007 06:09:26 -0400 (EDT)
- References: <200705230859.EAA23180@smc.vnet.net>
> 4. At work, I haven't had to resort to other programs because
> Mathematica wasn't the best choice. This is extremely nice. BTW,
> There's a "temporal" advantage with procedural programming that hasn't
> been apparant to me in functional or rule. Still working on it. Maybe
> someone can help. If I have
> lis={{1,10},{2,10},...{9,10},{11,20},{12,20}...{19,20}
>
> How do I use functional and/or rule to determine where the second
> number (lis[[i,2]]) jumped from 10 to 20 to 30 and save the pair.
> Assuming there was noise, I only want to store the first 10->20, then
> look for 20->30 and so on. So in time, I want my search to change as
> I progress through the list. Any input appreciated!
Here is a newbie approach:
In[36]:=
lst = Table[{Random[Integer,
{1, 100}], Random[
Integer, {9, 31}]},
{i, 1000}];
In[37]:=
ctl = {10, 20, 30, 40};
In[40]:=
First[Last[Reap[i = 1; j = 1;
While[i <= Length[lst],
If[lst[[i,2]] ==
ctl[[j]],
Sow[{i, lst[[i]]}];
j++; , Null];
i++; ]]]]
Out[40]=
{{3, {99, 10}},
{115, {49, 20}},
{127, {20, 30}}}
First part of an element show what position the element occurred in
lst, the second part is the element itself.
J=E1nos
----------------------------------------------
Trying to argue with a politician is like lifting up the head of a
corpse.
(S. Lem: His Master Voice)
- References:
- Mathematica 6.0 easier for me ... (small review)
- From: Paul@desinc.com
- Mathematica 6.0 easier for me ... (small review)