# Dynamically set several values in a list at once

I am attempting to create a threshold which can be manually adjusted when necessary, but otherwise is assumed to be constant. This corresponds to a list of values, wherein all later values are set equal to the current one, which is manually adjustable.

I have a working draft of this:

d=ConstantArray[0.5,6];(*Initial Values*)
DynamicModule[{l},
l=Length[d];
SlideView[
Table[With[{i=i},
Grid[{{VerticalSlider[Dynamic[d[[i]]]],(*Manually Change Values*)
Dynamic[ListLinePlot[d,PlotRange->{All,{0,1}}]]},(*Output*)
{Dynamic[Table[d[[j]]=d[[i]],{j,i,l}]],SpanFromLeft}}]],{i,l}]]]


However, it has issues with being VERY slow (the real data will have many more points than 6), and seems to require that I display the values themselves when setting them (this is possibly easy to fix, but I haven't found it yet). Does anyone know of a faster/better method?

• You can get rid of the inner table and just do d[[i ;; l]] = d[[i]]. If you want to be able to move the slider without loads of updates, try setting the UpdateInterval on the dynamics to a higher number. Use a semicolon to disable the output display of the values - you also don't need the final dynamic if I understand your problem correctly. – flinty Aug 10 at 15:04

Below the behavior differs slightly from the OP in that the array d is not updated when a new slide is chosen. The OP's method was causing continuous updating, which slowed the app's responsiveness. Here the update is within the Dynamic[] update function, which triggers just one update per slider move. One can shave a little time off using Graphics[] instead of ListLinePlot[]. However, ListLinePlot[] is more convenient and probably fast enough. Only testing on the actual use-case can confirm.

d = ConstantArray[0.5, 6];(*Initial Values*)
DynamicModule[{l},
l = Length[d];
SlideView[
Table[With[{i = i},
Grid[{
{VerticalSlider[
Dynamic[d[[i]], (d[[i ;; l]] = #) &]
](*Manually Change Values*)
,
Dynamic[ListLinePlot[d,
PlotRange -> {All, {0, 1}}]](*Output*)
},
{Dynamic[d[[i ;;]]]
, SpanFromLeft}}]
], {i, l}]
]]

• Cool! This is exactly what I was looking for. – ChaSta Aug 11 at 6:39

Is this what you are trying to achieve?

d = ConstantArray[0.5, 99];
modifyd[i_?IntegerQ, value_?NumericQ] := (d[[i]] = value; Join[d[[;; i]], d[[i]] &/@Range[Length@d - i]])
Manipulate[ListLinePlot[modifyd[i, value], PlotRange -> {All, {0, 1}}], {{i,Length@d}, 1, Length@d,1}, {{value, 0.5}, 0, 1}]


• Very cool idea to use manipulate instead of dynamic! – ChaSta Aug 11 at 6:44
• @ChaSta fwiw I hardly if ever use Dynamic in these cases apart from reading out values. Manipulate is my go to, & Mr Puh shows a great example of how one can do this! – CA Trevillian Aug 13 at 1:20