# Dynamically updating only the Manipulate local variable

Say I have an array of data arrays, assigned to a temporary variable dat, and I'd like to switch between plots of the arrays using Manipulate. For example:

RandomData := Table[RandomReal[], {ii, 1, 3}, {jj, 1, 10}];
dat = RandomData
Manipulate[
ListPlot[
dat[[ii]]
]
, {ii, 1, Length@dat, 1}]


Later, I generate another set of data arrays, and I want the same kind of dynamic plot. But I'd like to assign the data to the same temporary variable and reuse the plotting code to avoid needing to rename all the data variables within the Manipulate block (in general, the block could be long and complicated with many calls to dat).

dat = RandomData
Manipulate[
ListPlot[
dat[[ii]]
]
, {ii, 1, Length@dat, 1}]


The problem, of course, is that if I reassign a new value to dat, then the earlier Manipulate plot updates with the new value. But I would like both Manipulate outputs to show the value of dat as it was when the Manipulate block was called!

Is there a way to restrict the dynamic updating only to the local variable ii (i.e. to disable updating the variable dat)? Or is there perhaps an entirely different way to go about this, with Module, perhaps?

## 1 Answer

You can scope the updating of dat. e.g.

DynamicModule[{dat = RandomData},
Manipulate[ListPlot[dat[[ii]]], {ii, 1, Length@dat, 1}]]

• Ahh, I knew Mathematica somehow had my back! Thank you. Jan 6 at 18:42