Re: design question, how to have a set of manipulate controls, but have separate expression associated with each control?

*To*: mathgroup at smc.vnet.net*Subject*: [mg81108] Re: design question, how to have a set of manipulate controls, but have separate expression associated with each control?*From*: "Nasser Abbasi" <nma at 12000.org>*Date*: Wed, 12 Sep 2007 03:53:39 -0400 (EDT)*References*: <fc5n1u$qt7$1@smc.vnet.net>

"Nasser Abbasi" <nma at 12000.org> wrote in message news:fc5n1u$qt7$1 at smc.vnet.net... > hi; > > There is a design problem I am trying to solve. SNIP I got a helpful email suggesting to use a unamed Module (this will then act as global place to save parameters, and then check if each input has changed from last time. I modified the code send to me, and this is the type of solution I am considering now based on the template send to me in the email: First I check if first time being called, if so, I do all the work, saving the results in the global parameters, and make sure the firstTime flag is now False. Next time called, check to see which parameter is changed. This assumes ONLY one parameter can be changed at a time in the call. This I need to make sure about, but the way Manipulate works now, this seems correct, since each time I modify a manipulate control, it right away calls the process function before I get the chance to chance the second control. So If I had 2 controls, and I changed one, then process[] will always be called with at most one parameter changed from last time. Again, thanks for the emailer who send me the answer for the idea of using global manipulate and flags. I did think a little about this before, but I am thinking in a large amount of code, this could get messy with too many checks all over the place, but it seems for now this is the only way to solve this design problem. ps. on a side note: when I save as text the code into my email message, I can now indent it as I want to make it clearer to see, I wish I could do this inside Notebook as well. -------- code ----- Module[{firstTime = True, savedn1, savedn2, savedg1, savedg2, proc}, proc[n1_, n2__] := Module[{}, Which[ firstTime, {firstTime = False; savedg1 = Plot[Sin[n1*t], {t, -3*Pi, 3*Pi}, PlotStyle -> Red]; savedg2 = Plot[Cos[n2*t], {t, -3*Pi, 3*Pi}, PlotStyle -> Blue]; savedn1 = n1; savedn2 = n2 }, True, If[savedn1 === n1, {savedn2 = n2; savedg2 = Plot[Cos[n2*t], {t, -3*Pi, 3*Pi}, PlotStyle -> Blue]}, {savedn1 = n1; savedg1 = Plot[Sin[n1*t], {t, -3*Pi, 3*Pi},PlotStyle -> Red]} ] ]; Show[{savedg1, savedg2}, PlotRange -> All ] ] ] Manipulate[proc[n1, n2], {n1, 0.1, 1, 0.1}, {n2, 0.1, 1, 0.1}] -- end code ----