Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I have a Manipulate control, the main element of which is a single slider. Moving the one slider triggers calls to two functions - one which is evaluated very quickly, the other more slowly. I'd like to see 'live' update ( i.e. ContinuousAction->True ) for the fast one, but would only like to update the slow one when the mouse is released. Is there a simple way to achieve this?

Thanks in advance!

share|improve this question
add comment

3 Answers

Yes. Each control can have its own ContinuousAction option. As follows:

Manipulate[{x, y, z},
 {{x, 0, "x"}, 0, 10, 1, ContinuousAction -> True},
 {{y, 0, "y"}, 0, 10, 1, ContinuousAction -> False},
 {{z, 0, "z"}, 0, 10, 1},
 ContinuousAction -> True
 ]

The inner options take over from the common options. So in the above, z will use True but y will use False since it is an inner option.

Update this is a follow up on the comment below. I am not quite sure what is the problem we are solving exactly. But I think then what you want is simply to use ControlActive

http://reference.wolfram.com/mathematica/ref/ControlActive.html

ControlActive can be used to switch between a faster computation to be 
done while controls like sliders are being moved, and a slower 
computation to be done once the controls are released.

If this sounds like what you want, I'll be happy to make you an example using it if you tell me more about what these actions you want to do, which one is slow and which is fast. (help also have more examples on it, but feel free to follow up if it is not clear)

I understood the question first as you have 2 control variables and want to control each on its own.

share|improve this answer
    
Thanks - another simple thing I didn't know! –  Cuboid Dec 12 '12 at 10:06
1  
...ah...however...apologies, perhaps I didn't explain the problem. I have only one slider - but two things respond to the value of the slider - I want to make only one of those thing react in real-time, whilst the other waits for the slider to be released. –  Cuboid Dec 12 '12 at 10:42
    
In summary, I move a slider which changes the position of a Locator on a ListLinePlot. No problem there - that's fast. But the slider also sends a command to an external app. This is too slow to evaluate at every slider step, so I only want to send the command once the slider is released. –  Cuboid Dec 12 '12 at 21:48
add comment

This is not a full answer to your question, however I'd just like to add how this can be solved outside of Manipulate, perhaps someone can translate this into using Manipulate. As I understand it you problem is that you dynamically display both fast[a] and slow[a] while interactively updating a, which means the control waits for slow[a] to finish constantly. You can avoid this by making another variable that's only updated upon completion and then use that for the slow update:

  fast[a_] := a
  slow[a_] := (Pause[0.5]; a)

So rather than having

 {Dynamic@fast[a], Dynamic@slow[a]}]
 Slide[Dynamic[a],{0,1}]

You should have

 Slider[Dynamic[a, {(a = #) &, (b = #) &}], {0, 1}]
 {Dynamic@fast[a], Dynamic@slow[a]}]

Updated

to correct error caught by Mr. Wizard. Previusly used Dynamic[{fast[a],slow[b]}] to see the results which defies the point of letting them update independently.

share|improve this answer
    
Thanks - yes, that's an accurate description of the problem. This also works: Slider[Dynamic[ x, {None, Function[{v, e}, Print@fast[v], HoldRest], Function[{v, e}, Print@slow[v], HoldRest]}]] –  Cuboid Dec 12 '12 at 11:12
    
Oops, no it doesn't, no live update of the slider graphic itself. This one works: Slider[Dynamic[ x, {None, Automatic, Function[{v, e}, Print@slow[v], HoldRest]}]] –  Cuboid Dec 12 '12 at 11:19
1  
This works much better on my system with: {Dynamic @ fast[a], Dynamic @ slow[b]} –  Mr.Wizard Dec 12 '12 at 14:20
    
@Mr.Wizard Indeed, and it seems like that was also what I used in my testing. When under the same Dynamic slow[b] is called again because it updates both and not just the one depending on a. Thanks for the catch. –  jVincent Dec 12 '12 at 14:34
add comment

What you could do as well to indicate progress whilst your slow function is running:

Manipulate[ControlActive["calculating...", Pause[.5]; x], {x, 0, 1} ]

I did put here Pause[] as a replacement.

A more elaborate example would be the color curve of a complex phase (although this is no problem for Mathematica), but it shows the idea:

Manipulate[
  ControlActive["calculating...", _; 
  Plot[Abs[Zeta[1/2 + I a*t]], {t, -20, 20}, 
  ColorFunction -> Function[{t}, Hue[Rescale[Arg[Zeta[1/2 + I t]], {-Pi, Pi}]]], 
  ColorFunctionScaling -> False, Filling -> Axis]], {a, 1, 2}]
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.