Welcome to MMA SE! So, one way to do this is to actually treat the manipulated variable
as a string, and then parse it into your "real" variable in the code.
So, to do that, we're going to make two quick functions: one to convert lists to strings-without-brackets, and one to convert back.
ListToString[l_List] := StringTake[ToString[l], {2, -2}]
StringToList[s_String] := ToExpression["{" <> StringTrim[s,","] <> "}"]
In the first, it takes characters 2
to the penultimate one (-2
), thus excluding the braces at either end, and in the second, it string-joins (<>
) curly braces at either end and then parses it as a Mathematica expression via ToExpression
.
You might be wondering why StringTrim[s, ","]
is in there; that's just to trim off any trailing commas if your user forgets! (E.g. if their input is "1,2,3," and they forgot to delete the last comma; this will take care of that behind the scenes for them.)
So, inside the Manipulate
, at the start of the code labeled (*my code here*)
in your question, you'll want to insert the following:
realvariable = StringToList[strvariable]; (*my code here*)
This will parse your input whenever your user presses Enter
.
Now change your Manipulate
variable specification to
{{strvariable, ListToString[{50,60,70,80,90,95,99}]}, InputField[#, String] &}
Using InputField[#, String] &
will make `InputField format the string nicely, without quotes.
Also, as a note: it would be wise to put this realvariable
in a Module
, so that the variable realvariable
is trapped inside the manipulate, e.g.
Manipulate[
Module[{realvariable},
realvariable = StringToList[strvariable];
(*my code here*)
],
{{strvariable, ListToString[{50,60,70,80,90,95,99}]},
InputField[#, String] &}
]
Let me know if it's unclear how any of this works!
Manipulate[(*my code here*)variable, {variable, {50, 60, 70, 80, 90, 95, 99}}]
? $\endgroup$