Retrieving data from slider

I've been using GUIDE and I'm having trouble getting the value from the slider.
In the generated function
function slider1_Callback(hObject, eventdata, handles)
I can get the value with
sliderValue = get(handles.slider1,'Value')
But if I try using that in a user defined function I get this error:
??? Undefined variable "handles" or
class "handles.slider1".
Did I miss something?

 Akzeptierte Antwort

Matt Fig
Matt Fig am 2 Apr. 2011

0 Stimmen

In your user defined function doesn't accept the same three arguments, you will get this error. .
.
.
EDIT
Open the GUI with GUIDE. Double click on the slider to open the property editor. In the callback field, put this:
fun(gcbo,[],guidata(gcbo))
Where fun is the name of your function. fun will have to take three arguments just like shown:
function fun(hObject, eventdata, handles)

2 Kommentare

t
t am 2 Apr. 2011
Do you mean like this?
function fun(hObject, eventdata, handles)
sliderValue = get(handles.slider1,'Value')
This gives me
??? Input argument "handles" is
undefined.
Matt Fig
Matt Fig am 2 Apr. 2011
How are you assigning this callback to the slider?

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

t
t am 2 Apr. 2011

0 Stimmen

Like I posted in the comment above, I tried putting the same arguments in the function parameters
function fun(hObject, eventdata, handles)
sliderValue = get(handles.slider1,'Value')
and I get
??? Input argument "handles" is
undefined.

4 Kommentare

Matt Fig
Matt Fig am 2 Apr. 2011
But how are you telling the GUI to call your function fun? And where is fun, in the GUI M-file, or outside?
t
t am 2 Apr. 2011
I've tried using fun() in the slider itself and on a button press just to test it.
fun() is in the GUI .m file, I'm doing everything in the same GUIDE generated .m file.
Matt Fig
Matt Fig am 2 Apr. 2011
See my above answer...
t
t am 2 Apr. 2011
I guess that works but it's really not an appropriate solution. The data needs to be accessed by several functions, all called using the GUI at different times.
I will have to use global variable as I've been wasting a lot of time trying to work out how data is stored and retrieved, which I have to say is rather unintuitive and difficult to do (for such a simple process).
Thanks a lot for helping.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Interactive Control and Callbacks finden Sie in Hilfe-Center und File Exchange

Tags

Gefragt:

t
t
am 2 Apr. 2011

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by