0

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

larry
  • 725
  • 3
  • 11
  • I think the best way to achieve what you want would be to manually add your preferred values to the Initialization option within Manipulate. – MarcoB Oct 16 '21 at 21:05
  • 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? – Lukas Lang Oct 17 '21 at 12:42
  • You can Bookmark a setting with the + popup menu in the upper right corner of a Manipulate. Possible duplicate: https://mathematica.stackexchange.com/a/17988 -- I do this for classroom demonstrations. Also related: https://mathematica.stackexchange.com/a/56368 – Michael E2 Oct 17 '21 at 14:20
  • 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.) – Michael E2 Oct 17 '21 at 14:32
  • See http://reference.wolfram.com/language/ref/Bookmarks.html – Michael E2 Oct 17 '21 at 14:36
  • Sorry, things keep coming up in my mind. Let me know if any of these ideas work for you: Put this right after the Manipulate output after you have saved some bookmarks to retrieve the saved the Bookmarks option setting. You can then edit them and add the edited Bookmarks option to Manipulate. A Bookmarks setting does not have to set all controls. So you could have Bookmarks -> {"Setting 1" :> {a = 2; c = 7}} that skips b, d etc. – Michael E2 Oct 17 '21 at 14:52
  • sorry for the late reply, I had been overwhelmed with some urgent work these days, and just had the chance to come back to this issue. The Bookmark option is exactly what I'm looking for; after I paste the bookmark, I can add it as an option of Manipulate, then I can retrieve the status of the controls later on. Moreover, I can further change the values of any of the controls. These are all I need. – larry Oct 27 '21 at 03:32

1 Answers1

1

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.

Trev
  • 763
  • 3
  • 8
  • 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. – larry Oct 27 '21 at 04:39