Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Linking a Slider to Edit Box

Subject: Linking a Slider to Edit Box

From: Phil Goh

Date: 3 Sep, 2007 18:33:32

Message: 1 of 7

I'm dabbling with creating GUIs in Matlab. I'm trying to create a very simple GUI
that consists of a slider and a text box. What I would like to do is for the slider
to update the value of the text box and the text box to update the position of
the slider.

I'm able to retrieve the data from the text box and slider with the get(hObject,
'Value') function in their respective callback functions, but I do not know how to
trigger the update. How do I update the value of the textbox in the slider
callback function? and vice versa?

Any help would be much appreciated.

Phil

Subject: Linking a Slider to Edit Box

From: Jerome Briot

Date: 3 Sep, 2007 18:42:07

Message: 2 of 7

Hi,

use sliderPanel from the FEX :

http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=13845&objectType=file

Jérôme

Subject: Linking a Slider to Edit Box

From: Phil Goh

Date: 3 Sep, 2007 19:22:12

Message: 3 of 7

"Jerome Briot" <dutmatlab@yahoo.fr> wrote in message <fbhkhv$rtg
$1@fred.mathworks.com>...
> Hi,
>
> use sliderPanel from the FEX :
>
> http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?
objectId=13845&objectType=file
>
> Jérôme


Hi, thanks for that component. But that's not what I'm looking for. I'm a novice
to the whole GUI thing and was looking for a way to do it programmatically and
not resort to using someone else's component. The reason I want to do this is to
get a feel for the GUI API in Matlab.

Thanks
Phil

Subject: Linking a Slider to Edit Box

From: Lorenzo

Date: 3 Sep, 2007 21:38:24

Message: 4 of 7

"Phil Goh" <pgnator@googlemail.com> wrote in message
<fbhmt4$86u$1@fred.mathworks.com>...
> "Jerome Briot" <dutmatlab@yahoo.fr> wrote in message <fbhkhv$rtg
> $1@fred.mathworks.com>...
> > Hi,
> >
> > use sliderPanel from the FEX :
> >
> > http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?
> objectId=13845&objectType=file
> >
> > Jérôme
>
>
> Hi, thanks for that component. But that's not what I'm looking for. I'm a
novice
> to the whole GUI thing and was looking for a way to do it programmatically
and
> not resort to using someone else's component. The reason I want to do this
is to
> get a feel for the GUI API in Matlab.
>
> Thanks
> Phil

What about something like this:

(in the edit callback)
textValue = str2num( get(editHandle,'String') )
set(sliderHandle,'Value',textValue)

(in the slider callback)
sliderValue = num2str( get(sliderHandle,'Value') )
set(editHandle,'String', sliderValue)

Is that what you're looking for?
Lorenzo

Subject: Linking a Slider to Edit Box

From: Phil Goh

Date: 4 Sep, 2007 08:22:04

Message: 5 of 7

> What about something like this:
>
> (in the edit callback)
> textValue = str2num( get(editHandle,'String') )
> set(sliderHandle,'Value',textValue)
>
> (in the slider callback)
> sliderValue = num2str( get(sliderHandle,'Value') )
> set(editHandle,'String', sliderValue)
>
> Is that what you're looking for?
> Lorenzo


That is similar to what I've ended up doing. I store the hObjects of the slider
and edit box in the handle in their respective CreateFcn. This didn't work
before and hence my post, but since then I've discovered I need to insert a
call to guidata, which updates the value of handle.

So all works now. Thanks a bunch.

Phil

Subject: Linking a Slider to Edit Box

From: Paul Mennen

Date: 4 Sep, 2007 22:53:03

Message: 6 of 7

> use sliderPanel from the FEX :
http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=13845&objectType=file
> Jérôme

Another slider tool from the FEX is inside the plt routine:
http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=4936&objectType=file
In the plt help file, go to "command line arguments",
"auxiliary plt functions", "slider" for a description of
the calling sequence. There are several .m examples in
the demo folder that use this pseudo slider object.

The plt slider object combines 3 things, the slider,
the edit box, and (optionally) a slider label, which
is often needed when there are multiple sliders or other
controls.

The plt slider also provides many modes of operation, even
including a logarithmic movement mode (in case you just want
to allow powers of 2 as an example).

I see that you want to program it yourself, although you
may get some good ideas from plt.

~Paul

Subject: Linking a Slider to Edit Box

From: *- Jessica -*

Date: 17 Sep, 2007 12:35:49

Message: 7 of 7

GUI with slider panels

Hi,
I worked with Matlab in the weekend to find out how to use the sliderPanel from Brett Shoelson (http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=13845&objectType=file), but I have still problems with that. When I change something or copy the code into my GUI, than nothing works anymore.

I would like to have a sliderPanel like the "main" one in Bretts example with an additional feature: when I use the first slider and put the slider to the value of 15 then the second slider should start with 16.

Paul Mennen use that kind of feature in his "winplt" file, (http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=4936&objectType=file) but I am a rookie in Matlab and have no idea how to modify the code.

Can anyone help me to figure out how to do it?

Thanks in advance
Regards
Jessica

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us