This Manipulate
program below allows the user to enter points on a LocatorPane
and then draws a line through the points.
The Manipulate
has an Initialization
, where the programmer can define initial values for the points. The initial values are the variable ipts
in the code below. What I observe is that the first time I evaluate the cell, the Manipulate works as expected. But, if I change the initial points and then evaluate the cell, the Manipulate shows the previous values. After evaluating the cells with the Manipulate definition a second time, the plots shows the revised values.
This thread seems to discuss the same issue,How to eliminate the need to double evaluate a manipulate , but applying those answers to this question isn't clear to me.
Suspect that I am misunderstanding some fundamental concept about how initialization works. Could someone point out how to revise the code and/or a discussion of what is going on here?
myTest2 = Manipulate[
(*User points*)
posSorted = Sort[pos];
xMin = Min[posSorted[[All, 1]] ];
xMax = Max[posSorted[[All, 1]] ];
gvfuncUser = Interpolation[posSorted, InterpolationOrder -> 1];
myPlot = Plot[gvfuncUser[x], {x, xMin, xMax},
PlotRange -> {{0, 1}, {0, 1}}, Frame -> True, ImageSize -> 400];
Grid[{
{LocatorPane[Dynamic@pos, myPlot, LocatorAutoCreate -> True,
ContinuousAction -> False] }
}]
,
(*list of controls*)
{{pos, ipts}, ControlType -> None}
(*Initialization*)
, TrackedSymbols :> {pos, ipts}
, Initialization :> (
ipts = {{0.15, 0.35}, {0.25, 0.15}, {0.50, 0.17}, {0.75,0.18}, {1, 1}};
posSorted = {}; (*do this so that posSorted is local to this Manipulate (?) *)
gvfuncUser = {};
)
, SynchronousUpdating -> False
];
myTest2
In summary, to reproduce the question
- Evaluate the cells
- Change the values of ipts, for example, change the first point to {0.15, 0.05}
- Evaluate the cells, (the displayed points will not change to the revised values)
- valuate the cells, (the displayed points will change to the revised values)
Manipulate[..]
again but keeping the dynamic content alive, the initialization will not be evaluated. The reset of the data can be done by trivial addition of theipts={...}
before theManipulate
code. $\endgroup$