Creating Graphical User Interfaces    

Sliders

Sliders accept numeric input within a specific range by enabling the user to move a sliding bar. Users move the bar by pressing the mouse button and dragging the slide, by clicking in the trough, or by clicking an arrow. The location of the bar indicates a numeric value.

Slider Orientation

You can orient the slider either horizontally or vertically by setting the relative width and height of the Position property:

For example, these settings create a horizontal slider.

Current Value, Range, and Step Size

There are four properties that control the range and step size of the slider:

The Value property contains the numeric value of the slider. You can set this property to specify an initial condition and query it in the slider's callback to obtain the value set by the user. For example, your callback could contain the statement

The Max and Min properties specify the slider's range (Max - Min).

The SliderStep property controls the amount the slider Value property changes when you click the mouse on the arrow button or on the slider trough. Specify SliderStep as a two-element vector. The default, [0.01 0.10], provides a 1 percent change for clicks on an arrow and a 10 percent change for clicks in the trough. The actual step size is a function of the slider step and the slider range.

Designing a Slider

Suppose you want to create a slider with the following behavior:

From these values you need to determine and set the Max, Min, SliderStep, and Value properties. You can do this by adding the following code to the initialization section of the GUI M-file (after the creation of the handles structure):

You can also assign the slider properties using the Property Inspector:

Triggering Callback Execution

The slider callback is executed when the user releases the mouse button.


  Static Text Frames