MathGroup Archive 2011

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

Search the Archive

Re: How to extract a pattern

  • To: mathgroup at smc.vnet.net
  • Subject: [mg119645] Re: How to extract a pattern
  • From: Bob Hanlon <hanlonr at cox.net>
  • Date: Thu, 16 Jun 2011 03:59:26 -0400 (EDT)
  • Reply-to: hanlonr at cox.net

filter[data_List, key_String] := Select[data, MemberQ[#, key] &];

data = {{"MEN(00)=", "total", "sa=", 3.717*10^-6, "[um]"}, {"Field", 
    "[m/s]:", 2.615, 80., 83., 51., 10., 6., 5., 66., 
    1.175}, {"Filtered", "[m/s]:", 1.2, 4.2, 2., 46., 520., 990., 
    800., 143., 862.}, {}, {"(iter)", "Filter", "A"}, {"lbl", 5, 2., 
    20., 20., 20., 2.}, {"mod", 5, 0., 0.6, 0., 0.7, 0.}, {"(iter)", 
    "Filter", "B"}, {"lbl", 1, 14., 14., 600., 660., 50., 20., 10., 
    15., 16., 1.}, {"mod", 10, 0., 0.14, 1., 0.97, 0.97, 0.9, 0.89, 
    0.7, 0.1, 0.}, {"(iter)", "Filter", "C"}, {"lbl", 5, 1., 1., 1., 
    1., 1.}, {"mod", 5, 0., 0.1, 1., 0.6, 0.6}, {"(iter)", "Filter", 
    "D"}, {"lbl", 7, 1., 1., 1., 1., 1., 1., 1.}, {"mod", 7, 0., 10., 
    0.1, 10., 0., 0.8, 0.}, {"(iter)", "Filter", "E"}, {"lbl", 5, 9., 
    9., 9., 9., 9.}, {"mod", 5, 0., 0.2, 7., 0.9, 0.}, {"(iter)", 
    "Filter", "F"}, {"lbl", 2, 3., 4.}, {"mod", 2, 1., 1.}, {"(iter)",
     "Filter", "G"}, {"lbl", 2, 3., 3.}, {"mod", 2, 1., 
    1.}, {"(iter)", "Filter", "H"}, {"lbl", 2, 1., 3.}, {"mod", 2, 1.,
     1.}, {"#"}};

filter[data, "Filter"]

{{"(iter)", "Filter", "A"}, {"(iter)", "Filter", "B"}, {"(iter)", 
  "Filter", "C"}, {"(iter)", "Filter", "D"}, {"(iter)", "Filter", 
  "E"}, {"(iter)", "Filter", "F"}, {"(iter)", "Filter", 
  "G"}, {"(iter)", "Filter", "H"}}

filter[data, "lbl"]

{{"lbl", 5, 2., 20., 20., 20., 2.}, {"lbl", 1, 14., 14., 600., 660., 
  50., 20., 10., 15., 16., 1.}, {"lbl", 5, 1., 1., 1., 1., 
  1.}, {"lbl", 7, 1., 1., 1., 1., 1., 1., 1.}, {"lbl", 5, 9., 9., 9., 
  9., 9.}, {"lbl", 2, 3., 4.}, {"lbl", 2, 3., 3.}, {"lbl", 2, 1., 3.}}

filter[data, "mod"]

{{"mod", 5, 0., 0.6, 0., 0.7, 0.}, {"mod", 10, 0., 0.14, 1., 0.97, 
  0.97, 0.9, 0.89, 0.7, 0.1, 0.}, {"mod", 5, 0., 0.1, 1., 0.6, 
  0.6}, {"mod", 7, 0., 10., 0.1, 10., 0., 0.8, 0.}, {"mod", 5, 0., 
  0.2, 7., 0.9, 0.}, {"mod", 2, 1., 1.}, {"mod", 2, 1., 1.}, {"mod", 
  2, 1., 1.}}


Bob Hanlon

---- Ted Sariyski <tsariysk at craft-tech.com> wrote: 

=============
Hi,
I have the following problem.  I have to extract from a file data 
structure which is specified by a label (e.g. "A"), a set of points 
("lbl") and the corresponding weights ("mod")  (example is attached).  
Data is berried within a lot of garbage. The only invariant structure in 
all files is e.g.:

{"(iter)","Filter", "A"}, {"lbl", 5, 2., 20., 20.,20., 2.}, {"mod", 5, 
0., 0.6, 0., 0.7, 0.}

where "ilter", "lbl" and "mod" are always present but  "{iter}" differs 
from file to file.  The first element after "lbl" and "mod" is the same 
- the number of point for this filter.

How can I extract only these list elements which contain "Filter" and 
"lbl" and "mod"?
Thanks in advance,
Ted


{{"MEN(00)=", "total", "sa=", 3.717*10^-6, "[um]"}, {"Field", "[m/s]:", 
2.615, 80., 83.,51., 10., 6., 5., 66.,1.175}, {"Filtered", "[m/s]:", 
1.2, 4.2, 2., 46., 520., 990., 800., 143., 862.}, {},
{"(iter)", "Filter", "A"}, {"lbl", 5, 2., 20., 20., 20., 2.}, {"mod", 5, 
0., 0.6, 0., 0.7, 0.},
{"(iter)", "Filter", "B"}, {"lbl", 1, 14., 14., 600.,660., 50., 20., 
10., 15., 16., 1.}, {"mod", 10, 0., 0.14, 1., 0.97, 0.97, 0.9, 0.89, 
0.7, 0.1, 0.},
{"(iter)", "Filter", "C"}, {"lbl", 5, 1., 1., 1., 1., 1.}, {"mod", 5, 
0., 0.1, 1., 0.6, 0.6},
{"(iter)", "Filter", "D"}, {"lbl", 7, 1., 1., 1., 1., 1., 1., 1.}, 
{"mod", 7, 0., 10., 0.1, 10., 0., 0.8, 0.},
{"(iter)", "Filter", "E"}, {"lbl", 5, 9.,9., 9., 9., 9.}, {"mod", 5, 0., 
0.2, 7., 0.9, 0.},
{"(iter)", "Filter", "F"}, {"lbl", 2, 3.,4.}, {"mod", 2, 1., 1.},
{"(iter)", "Filter", "G"}, {"lbl", 2, 3., 3.}, {"mod", 2, 1., 1.},
{"(iter)", "Filter", "H"}, {"lbl", 2, 1.,3.}, {"mod", 2, 1., 1.}, {"#"}}



  • Prev by Date: Re: Seaching in Pi a sequence. Looking for a faster method
  • Next by Date: Re: Partition a list based on columns
  • Previous by thread: Aw: Re: mathematica 8 and psfrag
  • Next by thread: Resolution of Images in Web Export