Is it possible to use Mathematica's manipulate to change variables that have already been declared?
Example:
changeme = 8;
p = SomeSortOfPlot[changeme];
manipulate[Show[p],{changeme,1,10}]
The basic idea is that I want to make a plot with a certain changable value but declare it outside of manipulate.
Any ideas?
One option is to use Dynamic[] and LocalizeVariables -> False.
Example:
changeme = 8;
p[x_] := Plot[Sin[t], {t, 1, x}];
{
Manipulate[p[changeme], {changeme, 2, 9}, LocalizeVariables -> False],
Dynamic[changeme] (* This line is NOT needed, inserted just to see the value *)
}
Evaluating "changeme" after the Manipulate action will retain the last Manipulate value.
HTH!
If you want anything reasonably complicated or flexible, it is best to use Dynamic
and DynamicModule
instead of Manipulate
. The only exception is if you're writing a demonstration.
For example - a very basic way of doing what you want is
(in fact you don't even need the Row
and Slider
if you want to just change changeme
by hand.)
changeme=8;
p[x_]:=Plot[Sin[t],{t,1,x}];
Row[{"x \[Element] (1, ",Dynamic[changeme],") ",Slider[Dynamic[changeme],{2,9}]}]
Dynamic[p[changeme]]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With