Re: how to partition a list
- To: mathgroup at smc.vnet.net
- Subject: [mg117357] Re: how to partition a list
- From: Chris Degnen <degnen at cwgsy.net>
- Date: Wed, 16 Mar 2011 06:26:20 -0500 (EST)
- References: <ilksc4$69u$1@smc.vnet.net> <201103141158.GAA07823@smc.vnet.net> <ilnhfj$odp$1@smc.vnet.net>
On Mar 15, 11:10 am, Ted Sariyski <tsari... at craft-tech.com> wrote: > Hi, > I have data with the following structure: the first element is the > number of variables. For each variable follow: > title,x_var,y_var,dummy,number of points, {points}. I want to extract > data for each variable. Coming from Fortran I tend to make a Do-cycle, > count for the current position and assign values one by one. Is there a > better approach to this problem? > Thanks, > --Ted > > data={{3}, {"T", "vs.", "Distance", "for", "part", 4}, {"Distance"}, > {"T"}, {1}, {5}, {0, 300.006}, {5, 300.006}, {10, 300.006}, {15, > 300.006}, {20, 300.006}, > {"P", vs.", "Distance", "for", "part", 4}, {"Distance"}, {"P"}, {1}, > {6}, {0, 1.00007}, {5, 1.00007}, {10, 1.00007}, {15, 1.00007}, {20, > 1.00007}, {25, 1.00007}, > {"CO2","vs.", "Distance", "for", "part", 4}, {"Distance"}, {"CO2"}, {1}, > {7}, {0, 0.000326099}, {5, 0.000326099}, {10, 0.000326099}, {15, > 0.000326099}, {20, 0.000326099}, {25, 0.000326099}, {30, 0.000326099}} Some pointers here. First step is to restructure your data: data = {{3}, {"T", "vs.", "Distance", "for", "part", 4}, {"Distance"}, {"T"}, {1}, {5}, {0, 300.006`}, {5, 300.006`}, {10, 300.006`}, {15, 300.006`}, {20, 300.006`}, {"P", "vs.", "Distance", "for", "part", 4}, {"Distance"}, {"P"}, {1}, {6}, {0, 1.00007`}, {5, 1.00007`}, {10, 1.00007`}, {15, 1.00007`}, {20, 1.00007`}, {25, 1.00007`}, {"CO2", "vs.", "Distance", "for", "part", 4}, {"Distance"}, {"CO2"}, {1}, {7}, {0, 0.000326099`}, {5, 0.000326099`}, {10, 0.000326099`}, {15, 0.000326099`}, {20, 0.000326099`}, {25, 0.000326099`}, {30, 0.000326099`}}; nrecords = data[[1, 1]]; data2 = Rest[data]; output = {}; Do[(title = data2[[1]]; xvar = data2[[2, 1]]; yvar = data2[[3, 1]]; npts = data2[[5, 1]]; pts = data2[[6 ;; 6 + npts - 1]]; AppendTo[output, {title, xvar, yvar, pts}]; data2 = Drop[data2, 5 + npts]), {nrecords}]; numberofrecords = Length[output]; Print["Number of records = " <> ToString[numberofrecords]]; yvars = output[[All, 3]]; Print[StringJoin["Y variables = ", Riffle[yvars, ", "]]]; numbersofpoints = Length /@ output[[All, 4]]; Print[StringJoin["Number of points in records = ", Riffle[ToString /@ numbersofpoints, ", "]]]; lastpoint = output[[3, 4, 7]]; Print["Last point in last record = " <> ToString[lastpoint]];
- References:
- Re: Export strings to .pdf
- From: Yves Klett <yves.klett@googlemail.com>
- Re: Export strings to .pdf