Re: Data Plotting With Less Typing
- To: mathgroup at smc.vnet.net
- Subject: [mg45341] Re: Data Plotting With Less Typing
- From: Steve Eichblatt <steveeichblatt at yahoo.com>
- Date: Thu, 1 Jan 2004 05:54:33 -0500 (EST)
- References: <bsrho9$qio$1@smc.vnet.net> <bsu1ec$8h2$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Thanks for all who responded for the tips.
I really like the syntax of this program, and it works great in some
cases. But there is one problem making it work for my application. If I
already have an expression called a (or b or c1, etc), then parse makes
a rule with the EVALUATED form of a (or b, etc) instead of just the
symbol a (or b...).
That kind of problem is what led me to use StringReplace and put
everything in quotes. Is there some way around that? I tried things like
"HoldForm" to prevent evaluation, but i couldn't figure it out.
Thanks again!
Here is an example:
a = Table[Random[Integer, 100], {10}];
parse[d : {__?AtomQ}] := {Thread[ToExpression@data[[1]] -> d]}
parse[expr_] := Flatten[expr /. parse /@ data]
select[expr_] := Flatten@Position[parse@expr, True]
extract[expr_, test_] := parse[expr][[select[test]]]
data = {{"a", "b", "c1", "c2", "d"}, {1.64657, 3.11775, 4.4374, 8.93891,
1.19198}, {5.5366, 3.5689, 1.32583, 2.6293, 2.38973}, {9.03042,
9.87567, 4.34064, 8.09357, 3.44279}, {5.43228, 4.7836, 8.12985,
3.94991, 2.15411}};
parse[Sin[a/b] + c1][[select[d < c2]]]
First[parse /@ data]
gives:
Out[161]=
{c1 + Sin[14/b], c1 + Sin[20/b],
c1 + Sin[41/b], c1 + Sin[89/b]}
Out[162]=
{{{0, 14, 20, 41, 89, 67, 19, 99, 80, 83} -> a,
b -> b, c1 -> c1, c2 -> c2, d -> d}}