Mathematica Asked by user2253054 on June 11, 2021
I am trying to generate a table of InputFields with a list of variables. I am generating the variable names on the fly as the lists I am dealing with have variable sizes.
len := 10
pv := Table[ToExpression["pv" <> ToString[n]], {n, len}]
ab := Table[
With[{n = n},
InputField[Dynamic[pv[[n]]], FieldHint -> "Value",
FieldSize -> 5]], {n, len}]
This generates the table of input fields that I want. However, there are two issues:
I have read the Dynamic and Control documentation, searched the web multiple times, etc. There is something basic that I am not understanding on the use of Dynamic here. Any help would be greatly appreciated.
Thanks
With these small modifications, the code works for me even on a manual change of the pvs
:
ClearAll[len, pv, ab];
len = 10;
pv = Table[Symbol["pv" <> ToString[n]], {n, len}];
ab = Table[
With[{n = n}, InputField[
Dynamic[pv[[n]]],
FieldHint -> "Value",
FieldSize -> 5
]],
{n, len}
];
Notice the use of Symbol
instead of ToExpression
, and the use of Set
instead of SetDelayed
.
EDIT
Notice, also, that you must change the values of the variables pvN
, not pv[[N]]
.
Answered by Shredderroy on June 11, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP