Inputting Dynamic Variables
- To: mathgroup at smc.vnet.net
- Subject: [mg103053] Inputting Dynamic Variables
- From: Hugh Goyder <h.g.d.goyder at cranfield.ac.uk>
- Date: Sat, 5 Sep 2009 05:38:00 -0400 (EDT)
I am trying to organize a set of dynamic variables that can be modified either by using an input field or by updating the variables from a file. When updating from a file I use a button. I have a large number of variables although in the toy example below I just give 3. The modules will end up in a private context. The idea below is that the function pp[] contains a list of all the variables in a held form. The list named vals can be obtained by reading from a file with new values updated from new files. Below I give an example that works. However, there must be a better way... Having a ClearAll in a button seems a poor method for getting back to symbols rather than values. Any suggestion for a better approach.? ReSet[] := DynamicModule[{}, Dynamic[TableForm[ Table[InputLine[pp[][[i]]], {i, Length[iv]}] ]] ] InputLine[{p_, q_}] := DynamicModule[{t}, ReleaseHold[ Row[{p, InputField[Dynamic[t]]}] /. t :> q] ] ButtonReSet[] := Button["New values", Module[{aa, bb}, ClearAll[a, b, c]; aa = ReleaseHold[pp[][[All, 2]]]; bb = pp[][[All, 1]] /. vals; Evaluate[aa] = bb;]] F[] := DynamicModule[{}, Dynamic[Plot[a x^2 + b x + c, {x, -1, 1}]] ] ClearAll[pp, a, b, c]; iv = {a, b, c}; pp[] := {{"coff a ", Hold[a]}, {"coff b ", Hold[b]}, {"coff c ", Hold [c]}}; vals = {"coff a " :> 2, "coff b " :> 3, "coff c " :> 4}; Dynamic[#] & /@ iv ReSet[] F[] ButtonReSet[]
- Follow-Ups:
- Re: Inputting Dynamic Variables
- From: Leonid Shifrin <lshifr@gmail.com>
- Re: Inputting Dynamic Variables