Hot answers tagged

34

The Advanced Dynamic Functionality in Mathematica documentation has the following example that looks like what you need. DynamicModule[{n = 5, data = Table[RandomReal[], {20}]}, Column[{ Slider[Dynamic[n], {1, 20, 1}], Dynamic[Grid[Table[With[{i = i}, {Slider[Dynamic[data[[i]]]], Dynamic[data[[i]]]}], {i, n}] ]]}]] It builds a list of controllers (...


10

Reanalysis My earlier assertions were incorrect or at least incomplete. I now believe the problem in your code originates because of a particular behavior that can be seen in this separate example: asc = <|foo -> <|bar -> <|baz -> 1|>|>|> <|foo -> <|bar -> <|baz -> 1|>|>|> asc[foo][bar][baz] = 2; asc ...


9

Here is a followup to my question, code based on the example provided by kguler. Note there is no longer any need for Manipulate[]— it is all handled by Dynamic[]. data = Table[RandomReal[], {5}]; DynamicModule[ {n = Length[data]}, Column[{ Dynamic[ Grid[ Table[ With[{i = i}, {i, Slider[Dynamic[data[[i]]]], ...


8

This is similar to kguler's solution, but it assumes that there is a more complex updating going on during slider-interaction (namely, both list and total are updated), to illustrate more realistic cases where a single Dynamic object might affect more than one variables. Also it shows how to use Map with a variable number of Slider-s. For localization and ...


8

Because I'm new to Mathematica, I thought it may be helpful to newer people to answer this question the way a "new user" may think about the problem without the use of the more compact symbols. Obviously, MichaelE2 has covered the gambit of options already, and the solution below is negligibly different from his "non-editable label" solution. To create the ...


8

Two, now three, ways: I think I'd recommend the first -- strike that -- maybe the third one at the end, but perhaps you have a reason for using SetPrecision, in which case, use the second. This first one works as is. One caveat: if the label is used as an input field, the number k will be set to a machine-precision number. Manipulate[ Plot[Cos[k x], {x, ...


8

This should give you a starting point: opt = {PlotStyle -> Orange, AxesLabel -> {"\[Mu]s", "V"}, ImageSize -> 300} Manipulate[ Plot[Sin[10/x], {x, 0, 5}, PlotRange -> {xInt, {vMin, vMax}}, Evaluate[opt]], {{vMax, 0}, -1, 1, VerticalSlider, Appearance -> "Labeled"}, {{vMin, -1}, -1, 1, VerticalSlider, Appearance -> "Labeled"}, {{xInt,...


8

Here is the example from TrackingFunction: Manipulate[x, {{x, 2}, 0, 100, 1, TrackingFunction -> (If[PrimeQ[#], x = #] &)}]


7

Keep slider linear and have another variable. Manipulate[ DynamicModule[{p = Prime[n]}, p], {n, 1, 10, 1, Appearance -> "Labeled"}] Or, specify a setter bar but then force slider. With[{k = 10}, Manipulate[n, {n, Prime /@ Range[k], ControlType -> Slider}]] Or, make a custom interactive structure without Manipulate. With[{k = 10}, ...


7

You can achieve this by using both Dynamic and Slider: {Slider[Dynamic[x], {list}], Dynamic[x]}


6

I do this all the time, but use small buttons next to the slider. This is handy when one wants to jump to specific value, and sometimes it is hard to get the slider to go there exactly without few hits and misses and one ends up opening the slider using "+" and typing in the value in the small window which is not very efficient sometimes. Here is an example ...


6

Another approach is to use Manipulate. It is designed to handle the problem you have presented and takes care of all that Dynamic stuff internally. Manipulate[ Plot[m/2 + Sum[ (2*m/(n*Pi)^2)*((-1)^n - 1)*(Cos[n*Pi*x/m]), {n, 3} ], {x, -m, m} ], {{m, 1}, 0.1, 5.0, Appearance -> "Labeled"} ]


6

Example DynamicModule[ {value = 10}, Panel @ Row @ { Slider[Dynamic @ value, {1, 100, 1}, ImageSize -> Small], InputField[Dynamic @ value, Enabled -> False, ImageSize -> {36, 18}], Button["-", value--], Button["+", value++] } ] Output EDIT In order to restrict Slider to a set of pre-defined values, please see ...


6

Example Manipulate[ i, {i, {0, 1, 2.22, 5, 141, 299}, Slider} ] Output Reference Manipulate


6

It seems like a bug. Here's fix, via explicitly constructing the slider (Manipulator): n =.; DynamicModule[{c, t, main, f}, Manipulate[ ControlActive[{x, y}, main[x, y]], {{x, c/2, "n1"}, 1, y - c, 1}, {{y, n - c/2, "n2"}, x + c, n, 1, Manipulator[#1, {x + c, n, 1}] &}, SynchronousUpdating -> False, Initialization :> ( n = 300; ...


6

You can tweak underlying Graphics: IntervalSlider[ Appearance -> {"ThumbAppearance" -> {Style["[", 18], None, Style["1000", 18]}} , BaseStyle -> { GraphicsBoxOptions -> { PlotRangePadding -> {{.1, .1}, Automatic} } } ]


6

You can also wrap the interval slider object with Style and use DefaultOptions to set PlotRangePaddding option values: s = IntervalSlider[Appearance -> {"ThumbAppearance" -> {Style["[", 18], None, Style["1000", 18]}}] Style[#, DefaultOptions -> {Graphics -> PlotRangePadding -> {{Automatic, .1}, Automatic}}] & @ s


5

You will need work with an interval slider in terms of AbsoluteTime values because such sliders only work with numeric objects. Here is a demonstration where a interval slider has the behavior you want. With[{ min0 = AbsoluteTime @ DateObject[{2015, 3, 8, 10, 0, 0.}], max0 = AbsoluteTime @ DateObject[{2015, 3, 8, 12, 30, 0.}], minT = AbsoluteTime @ ...


5

It could be as simple as this: Manipulate[ DateString[t], {t, DateObject[{2015, 1, 1, 12, 0}], DateObject[{2015, 1, 1, 22, 30}], Quantity[5, "Minutes"]}] Using DateObjects rather than a List to indicate a date & time seems to work.


5

Based on the documentation, Slider is the only control object used in your code that supports a list of expression as its settings. Here is a custom alternative. DynamicModule[{list = {0.001, 0.0025, 0.005, 0.006, 0.007, 0.008, 0.009, 0.01}, l}, Row[{ Slider[Dynamic@l, {list}], Spacer[5], InputField[Dynamic[l, If[MemberQ[list, #], l = #] &], ...


5

How about using a different object to control some variables? It's not exactly a Manipulate control but it can have the same effect: HorizontalGauge[Dynamic@{x, y, z}, {0, 100}] I haven't worked out the constraining of variables but this could be a useful start.


5

DynamicModule[ { pt1, pt2, dist , trackingFunction = Function[{val, sym} , If[Block[{sym = val}, dist >= 2], sym = val] , HoldRest ] } , Manipulate[ Graphics[{Point[Dynamic@pt1], Point[Dynamic@pt2]} , PlotRange -> 5, Frame -> True ] , {{x1, 0}, -5, 5, TrackingFunction :> trackingFunction} , {{y1, 0}, -5, 5, ...


4

You mean something like this? Manipulate[ Plot[Cos[k x], {x, 0, 2 Pi}, Frame -> True, Axes -> False, ImagePadding -> 30], Text[Style[ Grid[{ {Style["k", Italic], Spacer[2], Manipulator[Dynamic[k, {k = SetPrecision[#, 22]} &], {0, to, del}, ImageSize -> Tiny], Spacer[2], Dynamic[AccountingForm[k , (*choose ...


4

m = 1; Slider[Dynamic[m]] Dynamic[ Plot[ m/2 + Sum[ (2*m/(n*Pi)^2)*((-1)^n - 1)*(Cos[n*Pi*x/m]) , {n, 3}] , {x, -m, m} ] ] EDIT Follow @Amir's comments and read the documentation for Dynamic


4

You can specify exactly what you want using controls. Have a look at the Introduction to Control Objects tutorial. Manipulate[x, Row[{ Slider[Dynamic@x, {-100, 100, 0.001}], Button["\[LessLess]", x = Max[x - 0.01, -100]], Button["<", x = Max[x - 0.001, -100]], Button[">", x = Min[x + 0.001, 100]], Button["\[GreaterGreater]", x = Min[x +...


4

The problem is with Animator. When it is passed a list, the +/- buttons increment the index of the setting by about 5-10%. It seems to pick a "nice" increment that is 1, 2 or 5 times a power of 10. When the length of the list is less than 10, it does not behave well. It seems that an increment of 0 is what is sometimes calculated. (Personally, I would ...


4

A teeny modification to Smit's solution, to fit the requirements of the question: With[{lower = 0, higher = 1}, Column[ {HorizontalGauge[Dynamic[{x, y, z}, Function[{val}, {x, y, z} = Sort[val]]], {lower, higher}, ImageSize -> 400], Dynamic[{x, y, z}]}] ]


4

Perhaps not easy to find in the documentation, but answered clearly in the section called A Good Trick to Know in the tutorial, "An Introduction to Dynamic": This can be done with /. or with the somewhat peculiar but convenient idiomatic form demonstrated here. Table[With[{i = i}, Slider[Dynamic[data[[i]]]]], {i, 5}] This output shows that Dynamic ...


4

DynamicModule[ {g = {}, p = {}, dx, dy, sol, x0, y0, td = {-10, 10}} , dx := 1 - x y; dy = x - y^3 ; sol[{dx_, dy_}, {x0_, y0_}] := {u[t], v[t]} /. Quiet@First@ NDSolve[{u'[t] == dx /. {x -> u[t], y -> v[t]}, v'[t] == dy /. {x -> u[t], y -> v[t]}, u[0] == x0, v[0] == y0, WhenEvent[Abs[v[t]] > 2, "StopIntegration"]},...


3

Code: Manipulate[ x, {{x, 0, "X:"}, -100, 100, 0.001} ] Output: Reference: Manipulate Tutorial: Introduction to Manipulate


Only top voted, non community-wiki answers of a minimum length are eligible