6
$\begingroup$

I am looking for a command that will output a list of values that correspond to the current parameter values manually set on a particular Manipulate interface.

For example, lets say I create an interactive interface using this code:

 Manipulate[
 Plot[
 A*Sin[f*t + p],
 {t, 0, 2 Pi},
 PlotRange -> {{0, 2 Pi}, {-1, 1}}],
 {A, 0, 1}, {f, 1, 10}, {p, 0, 2 Pi}]

Then suppose I use the Manipulate interface to set the parameters to some values I like as in the instance shown in the this screen cap:

enter image description here

What I would like to do now is input some command that will output these parameter values that the interface is currently set to (in this case, A = .5, f = 6, p = 1.4).

Ideally, I would like a List in a new cell of the form

{0.5, 6, 1.4}

Perhaps some kind of Dynamic automatic updating feature would be nice too.

This will allow me to continue being lazy and not have to enter these values individually when I refer to them in later code. Thanks to anyone who helps!

$\endgroup$

2 Answers 2

9
$\begingroup$

Perhaps the simplest way is to introduce a global variable storing the Manipulate variables:

Manipulate[
 global = {A, f, p};
 Plot[A*Sin[f*t + p], {t, 0, 2 Pi}, 
  PlotRange -> {{0, 2 Pi}, {-1, 1}}],
 {A, 0, 1}, {f, 1, 10}, {p, 0, 2 Pi}]

From now on, we can query global in a different cell any time. If wrapped into Dynamic, it will be updated as the Manipulate is manipulated.

Dynamic@global
$\endgroup$
2
  • 1
    $\begingroup$ sometimes it is possible to overcomplicate the problem but this is certainly the most straight forward approach. $\endgroup$ Oct 28, 2012 at 8:56
  • $\begingroup$ This is exactly what I had in mind. Very simple indeed! Thank you $\endgroup$
    – smtsjhr
    Oct 28, 2012 at 22:32
8
$\begingroup$

If you just want A, f, and p dynamically displayed all the time and printed when desired then:

Manipulate[
 Column[{
   Row[{Button["print", 
      CellPrint[
       TextCell[Grid[{{"A =", A}, {"f =", f}, {"p =", p}}], "Text", 
        ShowStringCharacters -> False]]], {A, f, p}}],
   Plot[A*Sin[f*t + p], {t, 0, 2 Pi},
    PlotRange -> {{0, 2 Pi}, {-1, 1}}]
   }],
 {A, 0, 1},
 {f, 1, 10},
 {p, 0, 2 Pi}]

Because the values within the Manipulate are localized it is unclear what you mean by referring to them (the values) in later code.

One thing to do, if your application is to save these values for later use, would be to bookmark the settings which you can do once you click the little icon in the top right hand corner:

enter image description here

From there give the bookmark a name:

enter image description here

I called it "my settings", so now you can revert to these settings from any state simply by selecting "my settings".

enter image description here

You can paste the bookmarked settings if you want to use the values in other code. Another thing could be to paste a snapshot:

enter image description here

$\endgroup$
2
  • $\begingroup$ These methods definitely accomplish my objective and also offer a greater utility than I originally intended. Until now I was unaware of this "Bookmarks" feature that was always just a click away. Thank you for relieving me of my ignorance! $\endgroup$
    – smtsjhr
    Oct 28, 2012 at 22:36
  • $\begingroup$ +1 for the explanation of bookmarks. I ignored them so far! $\endgroup$ Oct 29, 2012 at 10:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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