I want to use Manipulate (I am open to other alternatives) to apply one of two different functions f or g to a set of values. The issue is that, I want to update the evaluation only when the user clicks on one of the button f or g. I came up with the following work around but I wonder if there is a better/standard way to implement such a thing?
Module[{val},
Manipulate[
val = Switch[op, "f", op = ""; f[x], "g", op = ""; g[x], "", val];
val, {x, {1, 2, 3}, Setter}, {op, {"f", "g"}, Setter},
TrackedSymbols -> {op}]
]
As a side question: is there any way to tell Manipulate to ignore the current evaluation and keep the last evaluated value?
DynamicModuleinstead ofModule– Ajasja Oct 15 '12 at 10:18novartheModulevariable is not the same asnovarlocalized withinManipulateand is not needed. If you wantvalto be stored then it should be aDynamicModule. – Mike Honeychurch Oct 15 '12 at 10:40novarin the DM is still redundant. – Mike Honeychurch Oct 15 '12 at 11:02Method->"Queued"for them which would make this work even when the evaluation offorgwould take long enough for an abort of the dynamic (which might be the case from what the OP mentioned in a comment). Asnovaris just a dummy variable, you could usevalinstead there and get rid of theDynamicModule: `Manipulate[val, {x, {1, 2, 3}, Setter}, {{val, "please click button...", "operator"}, Row[{Button["Call f", val = f[x]], Button["Call g", val = g[x]]}] &}] – Albert Retey Oct 15 '12 at 12:06Method->"Queued"the OP can solve a problem that I could well imagine him to see in the near future. Actually theButtonBarsolution of kguler has the same property, even by default... – Albert Retey Oct 15 '12 at 12:23