3
$\begingroup$

Is it possible to write a function that returns a set of values that are set by Manipulate?

For example, a function that returns a dataset of variables modified by Manipulate when an "Update" button is clicked. For example, would it be possible to return treatmentSpecRow from the EKSWaveformControl function below or make it accessible outside of the local scope of EKSWaveFormControl?

EKSWaveFormControl[] :=
  DynamicModule[{treatmentSpecRow},
    Manipulate[
      Plot[ctrlVdc + ctrlVac ctrlgFunc[2 π ctrlf t + ctrlPhi], {t, 0, 0.4}],
      {{ctrlgFunc, Sin, ""}, {Sin, Cos, Tan, Cot}},
      Delimiter,
      {{ctrlVac, 1.5, Subscript["V", "ac"]}, -10, 10}, 
      {{ctrlVdc, 0.5, Subscript["V", "dc"]}, -1, 1},
      Delimiter,
      {{ctrlf, 10, "Frequency"}, 0.001, 100},
      {{ctrlPhi, 0, "ϕ"}, 0, 2 π}, 
      Delimiter,
      Button["Update",
        treatmentSpecRow = 
          Dataset[Association @ 
            {Func -> ctrlgFunc, Vac -> ctrlVac, Vdc -> ctrlVdc, 
             ϕ -> ctrlPhi, ω -> 2 π ctrlf}]], 
       ControlPlacement -> Left,
       Paneled -> True,
       LocalizeVariables -> True]]
$\endgroup$
  • $\begingroup$ Here's a similar question: 15090. $\endgroup$ – Virgil May 1 '15 at 15:55
  • $\begingroup$ Hi m_goldberg - I have posted an example. In the example, I would like to obtain a Dataset of values changed during a Manipulate session. In the example I would like to return the treatmentSpecRow Dataset from EKSWaveFormControl[] when the Update button is clicked. This will be one of several controls in a complex computation that can be somewhat time consuming. I would like to let users set parameters in multiple controls, take all of the control settings and start the run with parameters from multiple controls. $\endgroup$ – Doug Kimzey May 1 '15 at 16:11
  • $\begingroup$ Manipulate has a feature that delivers almost what you want. It is Paste Snapshot, which appears on the Bookmarks/Autorun pop-up menu. Click on the (+) button at the upper right conner of the Manipulate panel. This writes the values you want, and some other stuff, to new input cell. $\endgroup$ – m_goldberg May 1 '15 at 16:45
  • $\begingroup$ Hi @m_goldberg, I wonder if there is a way to call the Paste Snapshot could be called programmatically. The reason being that many of the end-users will be running this via a CDF and will not be seasoned Mathematica users. If I could make save variables updated in Manipulate to a list available outside of the manipulate, that would be ideal. $\endgroup$ – Doug Kimzey May 1 '15 at 17:27
  • $\begingroup$ @DougKimzey so are you alive? $\endgroup$ – Kuba May 12 '15 at 7:26
1
$\begingroup$

I don't know how to do what you ask, but here is an alternative approach that you might use.

snapshots = {};
Manipulate[
  Plot[ctrlVdc + ctrlVac ctrlgFunc[2 π ctrlf t + ctrlPhi], {t, 0, 0.4}],
  {{ctrlgFunc, Sin, ""}, {Sin, Cos, Tan, Cot}},
  Delimiter,
  {{ctrlVac, 1.5, Subscript["V", "ac"]}, -10, 10}, 
  {{ctrlVdc, 0.5, Subscript["V", "dc"]}, -1, 1},
  Delimiter,
  {{ctrlf, 10, "Frequency"}, 0.001, 100},
  {{ctrlPhi, 0, "ϕ"}, 0, 2 π}, 
  Delimiter,
  Button["Update",
    snapshots = 
      {snapshots, <|Func -> ctrlgFunc, Vac -> ctrlVac, Vdc -> ctrlVdc, 
                    ϕ -> ctrlPhi, ω -> 2 π ctrlf|>}],
  ControlPlacement -> Left]

demo

Evaluate the following after the Manipulate panel appears if you want to see how snapshots changes each time Update is clicked.

Dynamic @ Column @ Flatten @ snapshots
<|Func -> Sin, Vac -> 1.5, Vdc -> 0.5, ϕ -> 0, ω -> 20 π|>}, 
<|Func -> Tan, Vac -> -6.3, Vdc -> 0.5, ϕ -> 0, ω -> 140.743|>

When you have all the snapshots you want, evaluate

ds = Dataset[Flatten @ snapshots]

dataset

The dataset is not displayed in a nice table form because you chose to have symbols for keys; you need to use string keys to get the nice looking table.

$\endgroup$
0
$\begingroup$

To make more automatic approach we can use some knowledge shared by MichaelE2: Manipulate: How to create custom reset Button automatically?

EKSWaveFormControl[] :=  Manipulate[
   Plot[ctrlVdc + ctrlVac ctrlgFunc[2 \[Pi] ctrlf t + ctrlPhi], {t, 0,
      0.4}], 
  {{ctrlgFunc, Sin, ""}, {Sin, Cos, Tan, Cot}}, 
   Delimiter, 
  {{ctrlVac, 1.5, Subscript["V", "ac"]}, -10,   10}, 
  {{ctrlVdc, 0.5, Subscript["V", "dc"]}, -1, 1}, 
   Delimiter, 
  {{ctrlf, 10, "Frequency"}, 0.001,  100}, 
  {{ctrlPhi, 0, "\[Phi]"}, 0, 2 \[Pi]}, 
   Delimiter,

  Button["Update", 
    externalVar =  Association[
      Cases[Typeset`specs,  
        Hold[s_Symbol] :> (StringTrim[SymbolName[Unevaluated@s],
                                      "$$" ~~ NumberString
                                     ] -> s), 
        \[Infinity]]]]



   ,
   ControlPlacement -> Left, Paneled -> True, 
   LocalizeVariables -> True]


EKSWaveFormControl[]
Dynamic @ externalVar
(*manipulate panel*)
<|ctrlgFunc->Sin,ctrlVac->6.45,ctrlVdc->0.5,ctrlf->10,ctrlPhi->0|>
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.