I have a set of variables which are used in various places in my calculations (solving a system, initial conditions, etc.). In order to make this easier to deal with, I want to make a control-like thing which makes them easier to manipulate, rather than just using long lists of unlabeled values such as
calculateValues[{0, 0, π, 0.5, 3}]
So far I have something like this:
This clearly doesn't work, and I expect in order to get it working properly I'll need to use Interpretation
or more Dynamic
incantations, but I can't figure out exactly what needs to happen. Any advice would be appreciated. Thanks in advance!
Answer
You could do
myControl[varNames_List, start_: 0] :=
myControl[varNames, ConstantArray[start, Length@varNames]]
myControl[varNames_List, start_List] :=
Interpretation[{vars = start},
Panel[Grid[{varNames,
Array[InputField[Dynamic@vars[[#]],
FieldSize -> {{0, Infinity}, 1}] &, Length@vars]}]], vars]
Now you can run that function to create a control myControl["a"~CharacterRange~"g"]
. Each instance will have its own values and they all evaluate to their values when supplied as input
Comments
Post a Comment