File Exchange

image thumbnail


version (6.02 KB) by

A new UICONTROL object with a slider as a child of a uipanel, with auto-linked edit box and labels.



View License

Editor's Note: This file was a File Exchange Pick of the Week

An indispensible uicontrol: linked slider, text, and labels all self-contained in a panel.
sliderHandle,panelHandle,editHandle] = sliderPanel(parent, PanelPVs, SliderPVs, EditPVs, LabelPVs, numFormat)
Creates a slider in a separate uipanel, with an associated interactive EditBox, and left and right labels showing the minimum and maximum values of the slider, respectively.

Moving the slider automatically updates the textbox, and vice versa. Both slider movement and text edits will trigger (non-recursively) the callback of the slider.
The EditBox automatically disallows the entry of non-numeric values, or of values outside of [min,max]. Attempts to enter disallowed values will be ignored.
Two syntaxes are supported. One gives FULL control over all elements of the sliderPanel, and a second provides easier access to a subset of the functionality.

UPDATE: Right-clicking the slider now resets the sliderPanel to its default (creation) value.

Comments and Ratings (5)


Scott (view profile)

Here are some more extensive tests and comments on the code:


{'title','Threshold','pos',[0.1 0.2 0.8 0.15],'fontweight','b','units','pixels'},...

get(e,{'string','value','userdata'}), get(s,'Value')
ans =
    '60' [0] '60'
ans =

%in your code you have a bug fix on line 393 that sets the editbox value, but there isn't a similar line earlier upon initialization, say after line 339 where the edithandle userdata is set

%Move the slider by hand to 25.3
get(e,{'string','value','userdata'}), get(s,'Value')

ans =
    '25.3' [0] '25.3'
ans =

%editbox value is not set inside the updateText() function


So it looks to me like the code could use a few more lines to keep the value in sync with the other two. But I was also wrong in how I thought it worked. I had assumed that there was more linkage than there is - that if I changed the slider value programmatically there was some internal callback that would align the editbox with it and vice versa. In thinking about it more, I have no idea how one would do this in matlab if changing it programmatically would not trigger an event (although if it is possible, it would be nice to know how). For my purposes, I'll just be sure to change the slider value and all three editbox settings together when I manipulate one programmatically.

Thanks for the widget, though. I never use sliders anymore without it.


Scott (view profile)

Programmatically changing the editbox or slider values gives me the following behaviors:


% this changes the value of the slider to 20 and also moves the slider. but neither the editbox value nor display changes.

%this changes the value of the editbox to 70, but the editbox display does not change and neither does the slider position of value.


Yogi (view profile)

i got it Brett, too basic it was..


Yogi (view profile)

hi Brett,can i specify property as "orientation"? i mean if i want vertical slider then which property will help me?

John D'Errico

Since most of the sliders I've ever generated also had exactly these uicontrols attached to them, this makes great sense. Thanks for posting it.

I tested it out in both R2006b and in R14SP1 (both on a Mac.) It worked nicely in R2006b, but in the older release, the slider bar would not move properly, and when the figure was resized, the slider bar moved to a different place in the figure. So there appear to be definite problems in older releases.


Updated license


Right-clicking now resets the slider to its default (creation) value.


Right-clicking the slider now resets the sliderPanel to its default (creation) value.


Now automatically includes right-click reset to default (initial) value!


Updated M file and license text file copyright to The MathWorks, Inc.


added copyright

MATLAB Release
MATLAB 7.3 (R2006b)

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video