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?

 채택된 답변

Matt Fig
Matt Fig 2011년 4월 2일

0 개 추천

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

t
t 2011년 4월 2일
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 2011년 4월 2일
How are you assigning this callback to the slider?

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

t
t 2011년 4월 2일

0 개 추천

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

Matt Fig
Matt Fig 2011년 4월 2일
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 2011년 4월 2일
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 2011년 4월 2일
See my above answer...
t
t 2011년 4월 2일
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.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

태그

질문:

t
t
2011년 4월 2일

Community Treasure Hunt

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

Start Hunting!

Translated by