4

I've created a function f and a slider:

Slider[Dynamic[y],{1,4}]

How to execute/call f each time the slider is dragged?

faysou
  • 10,999
  • 3
  • 50
  • 125
santhosh
  • 423
  • 3
  • 7
  • Still no code formatting or capitalization in your original question (other people were kind enough to edit)... – Ajasja Dec 12 '12 at 14:14

2 Answers2

10

Like this

Slider[Dynamic[y,(y=#;f[y])&],{1,4}]

You can can test using for example

f[y_]:=Print@y;

I advise you to look at the help of Dynamic that contains examples of other related features.

faysou
  • 10,999
  • 3
  • 50
  • 125
4

Another rout to take would be just using Manipulate. It will update content inside of it automatically in addition to automatically creating an interface.

f[y_] := y
Manipulate[f[y], {y, 1, 4}]

enter image description here

Vitaliy Kaurov
  • 73,078
  • 9
  • 204
  • 355