0
$\begingroup$

I’m using Manipulate[] to adjust several parameters, which will eventually generate some figures. After I get the desired view, I’d like to store the set of control parameters so that I can reuse them in the future.

Currently, I created two controls “recordControlParameters” and “userecordControlParameters” as flags, to let the code print out the list of control parameters as a list, and then paste their values to an assignment of these parameters at the beginning of the module, which could work, but the problem is, next time when I execute this code, I can no longer adjust any of these parameters if I turn on the “userecordControlParameters” mode.

I hope to find a way to be able to skip the assignment at the beginning of the code. For example, if I want to still adjust {b,c}, then I hope that, once I’m given this list at the beginning, I can skip the assignment of them.

The essense of this question is: given a list allvariables={a,b,c,d},variables2skip={b,d} and valueList={1,2,3,4}, with a,b,c,d already assigned to some nuemrical values by the control itself, how can we reassign a and c upon using allvariables and variables2skip and valueList?

Or is there any more elegant ways to cope with this?

Below is a minimal example (the real code has a large number of controls)

DynamicModule[{a, b, c, d, e, g, userecordedControlParameters, 
recordControlParameters}, 
Manipulate[
Module[{}, 
If[userecordedControlParameters == 
 1, {a, b, c, d} = {1, 2, 3, 0}]; 
If[recordControlParameters == 1, Print[{a, b, c, d}]];   
Plot[a*x^3 + b*x^2 + c*x + d, {x, -4, 4}]], 
Evaluate@manipulateControlLayoutUsingDivider[
 "Row"]@{Style["Amplitudes Sines", 15, Bold], {{a, 1, "a"}, 0, 
  3}, {{b, 1, "b"}, 0, 3}, Delimiter, 
 Delimiter, {{g, 1, "g"}, 0, 10}, Delimiter, {{e, 2, "e"}, 0, 5}, 
 Delimiter, {{c, 1, "c"}, 0, 4}, {{d, 0, "d"}, 0, 2}, 
 Delimiter, {{recordControlParameters, 0, 
   "recordControlParameters"}, {0, 
   1}}, {{userecordedControlParameters, 0, 
   "userecordedControlParameters"}, {0, 1}}}, Alignment -> Center,
 ControlPlacement -> Left]]

enter image description here

$\endgroup$
7
  • $\begingroup$ I think the best way to achieve what you want would be to manually add your preferred values to the Initialization option within Manipulate. $\endgroup$
    – MarcoB
    Oct 16 at 21:05
  • $\begingroup$ Did you try the bookmarks-feature? You can click the plus on the upper right corner to save and restore parameter th values. It's not as flexible as what you are asking for in the question, but maybe it's enough? $\endgroup$
    – Lukas Lang
    Oct 17 at 12:42
  • $\begingroup$ You can Bookmark a setting with the + popup menu in the upper right corner of a Manipulate. Possible duplicate: mathematica.stackexchange.com/a/17988 -- I do this for classroom demonstrations. Also related: mathematica.stackexchange.com/a/56368 $\endgroup$
    – Michael E2
    Oct 17 at 14:20
  • $\begingroup$ There is also a Paste Snapshot command in bookmarks menu, which may be sufficient for your purposes. It pastes a DynamicModule that constructs the Manipulate body without the controls or surrounding panel. (For that matter, Add to Bookmarks... from the bookmarks menu may be what you're looking for. Beware that those are saved in the Manipulate and go away if the cell is deleted or overwritten.) $\endgroup$
    – Michael E2
    Oct 17 at 14:32
  • $\begingroup$ See reference.wolfram.com/language/ref/Bookmarks.html $\endgroup$
    – Michael E2
    Oct 17 at 14:36
1
$\begingroup$

I haven't used this myself, but it looks like the SaveDefinitions option is what you want, if I understand you correctly...? Manipulate also has some other options that look helpful, like UnsavedVariables for those values you want overwritten each time.

Failing that, you're probably looking at doing the saving/loading manually using something like PersistentSymbol; you would write out to PersistentSymbol["myDataWhatever"] whenever the settings changed and/or you wanted to save their values, and then you can access that data again even in a later session, so it's just a matter of loading up the right settings in Initialization.

$\endgroup$
1
  • $\begingroup$ thanks for your suggestion; I have checked out their documentation, but didn't catch what they are used for. Anyway, using bookmarks is sufficient for my current question. $\endgroup$
    – larry
    Oct 27 at 4:39

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.