Using the structure inside Manipulate to control control variables, how to initialize

I'm not sure how to initialize the structure in Mathematica for use with Manipulate to help me better organize the many control variables that I have.

I will give some examples to help show the problem.

Here is the most basic manipulator:

method 1

Clear["Global`*"]
Manipulate[process[a, b],

 {{a, 1, "a"}, -10, 10, 1},
 {{b, 2, "b"}, -10, 10, 1},

 Initialization :> 
  {
   process[a_, b_] := Module[{}, Row[{"a=", a, " b=", b}]]
   }
 ]

In the demo I'm writing, I still have many controls. Some functions (such as the function called the process [] in the above) must ultimately be called with 15 or more arguments, which makes support difficult for me. (I have no choice about this, I can not refute it).

So, I'm trying to use a structure to collect this variable. Related question

" Mathematica

, : ( , Mathematica , , )

2

Clear["Global`*"]
Manipulate[process[myData],

 {{myData["a"], 1, "a"}, -10, 10, 1},
 {{myData["b"], 1, "b"}, -10, 10, 1},

 Initialization :> 
  {
   process[myData_] := 
    Module[{}, Row[{"a=", myData["a"], " b=", myData["b"]}]]
   }
 ]

.

Manipulate::vsform does not have the correct form for a variable specification

, , , , process [], :

3

Clear["Global`*"]
Manipulate[
 (
  myData["a"] = a;
  myData["b"] = b;

  process[myData]
  ),

 {{a, 1, "a"}, -10, 10, 1},
 {{b, 1, "b"}, -10, 10, 1},

 Initialization :> 
  {
   process[myData_] := 
    Module[{}, Row[{"a=", myData["a"], " b=", myData["b"]}]]
   }
 ]

. , , ,

Manipulate

(2) , , ! , , , . (2),

(2)

Clear["Global`*"]
Manipulate[process[myData],

 (*-- define 2 control variables, using the macro method --*)
 Evaluate@With[{s1 = Function[{struct},
      Grid[{
        {Manipulator[Dynamic[struct["a"]], {-20, 20, 0.1}]},
        {Manipulator[Dynamic[struct["b"]], {-2, 2, .5}]}
        }],
      HoldAll]
    },
   s1[myData]
   ],

 Initialization :> 
  {
   process[struct_] := Module[{},
     Text[Grid[{
        {"a=", struct["a"]},
        {" b=", struct["b"]}
        }]]
     ]
   }
 ]

, myData . , . , .

"", , myData , , Manipulate, :

(2) ,

Clear["Global`*"]
Manipulate[process[myData],

 (*-- define 2 control variables, using the macro method --*)
 Evaluate@With[{s1 = Function[{struct},
      Grid[{
        {Manipulator[Dynamic[struct["a"]], {-20, 20, 0.1}]},
        {Manipulator[Dynamic[struct["b"]], {-2, 2, .5}]}
        }],
      HoldAll]
    },
   s1[myData]
   ],

 Initialization :> 
  {

   myData["a"] = 1;   (* now OK, but mydata is global *)
   myData["b"] = 1;

   process[struct_] := Module[{},
     Text[Grid[{
        {"a=", struct["a"]},
        {" b=", struct["b"]}
        }]]
     ]
   }
 ]

myData Manipulate, , , ?

(2) , Manipulate, None control

Clear["Global`*"]
Manipulate[process[myData],

 (*-- define 2 control variables, using the macro method --*)
 Evaluate@With[{s1 = Function[{struct},
      Grid[{
        {Manipulator[Dynamic[struct["a"]], {-20, 20, 0.1}]},
        {Manipulator[Dynamic[struct["b"]], {-2, 2, .5}]}
        }],
      HoldAll]
    },
   s1[myData]
   ],

 {{myData["a"], 1}, None}, (*invalid syntax*)
 {{myData["b"], 1}, None},

 Initialization :> 
  {
   process[struct_] := Module[{},
     Text[Grid[{
        {"a=", struct["a"]},
        {" b=", struct["b"]}
        }]]
     ]
   }
 ]

, : myData (2) , ?

, , , Manipulate [..]. . Manipulate [...]

:

(3) , .

, , , ( , 20 !, 5 , "" , ). , , , .

"":

Manipulate[
 Module[{myData},

  (*fill in the struct *)
  myData["a"] = a;
  myData["b"] = b;
  myData["c"] = c;

  process[myData]
  ],
 (*-- define  control macro  --*)
 Evaluate@With[{s1 = Function[{var},
      Manipulator[Dynamic[var], {-20, 20, 0.1}], HoldAll]
    },
   Column[{s1[a], s1[b], s1[c]}]
   ],

 (*initialize fields of the struct, or the control variables*)
 {{a, 1}, None}, 
 {{b, 2}, None},
 {{c, 3}, None},

 Initialization :> 
  {
   process[myData_] := Module[{},
     Text[Grid[{
        {"a=", myData["a"]},
        {" b=", myData["b"]},
        {" c=", myData["c"]}
        }]]
     ]
   }
 ]

, Mathematica /, .

+5

All Articles