View License

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

» Watch video

Highlights from

5.0 | 2 ratings Rate this file 13 Downloads (last 30 days) File Size: 6.02 KB File ID: #13845 Version:
image thumbnail



Brett Shoelson (view profile)


02 Feb 2007 (Updated )

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

Editor's Notes:

This file was a File Exchange Pick of the Week

| Watch this File

File Information

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.


This file inspired Cqi Plotmatrix( Data,Varargin ), Segment Tool: An Interactive Gui For Segmenting Images, and Dynamical System Viewer.

MATLAB release MATLAB 7.3 (R2006b)
Other requirements Created with 2006b and 2007a. I think it's platform-independent. I'm not sure how recent ML needs to be.
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (5)
15 Apr 2015 Scott

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.

Comment only
15 Apr 2015 Scott

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.

Comment only
14 Sep 2012 Yogi

Yogi (view profile)

i got it Brett, too basic it was..

14 Sep 2012 Yogi

Yogi (view profile)

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

Comment only
05 Feb 2007 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.

04 May 2010 1.2

added copyright

21 Jun 2010 1.3

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

10 Oct 2012 1.4

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

29 Nov 2012 1.9

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

13 May 2013 1.12

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

01 Sep 2016

Updated license

Contact us