Extracting the value of a slider
112 views (last 30 days)
Show older comments
I created a slider using the GUIDE. I want to use the slider's numeric output as the input to another m-file, but I do not know how to get it so that I can use the sliders output for another file.
I have been looking around a lot and it seems that I have to do something with a callback function but I am not sure if I should put this in my slider code or my other m-file's code.
0 Comments
Answers (5)
Doug Hull
on 14 Jun 2011
The value of a slider is available when you use the get command on the handle of the slider. For instance:
>> h = uicontrol('style','slider')
h =
0.0123
>> get(h,'value')
ans =
0
%Mess with slider a bit
>> get(h,'value')
ans =
0.1000
The trick for you is getting the handle of the slider. For that, we need to know how you made the slider. It is easiest to do this when you already know the handle to the slider. Otherwise findobj might be helpful, or look into the handles structure if using the GUIDE.
0 Comments
Matt Tearle
on 14 Jun 2011
Your slider has a callback property that defines the function that will be called when the slider is moved. It's inside that function that you need to query the value property of the slider handle, as Doug says.
Example:
Callback function:
function slidercb(h,event)
val = get(h,'value')
% do something with the slider value
Somewhere else:
figure
uicontrol('units','normalized','position',[0.2,0.2,0.5,0.1],...
'style','slider','callback',@slidercb)
0 Comments
Oscar Machuca
on 2 Apr 2013
Im having the exact problem as you . But i didn't understand where did you write this code?
handles = guihandles(WaveLength)
%gets handles for figure and sets them to 'handles'
waveLen=get(handles.slider1,'Value')
% gets the number occupying the 'Value' of the figure 'slider1'
% in the
% handles structure
Do you write it on the same .m file or is it a new file . please post your code
0 Comments
See Also
Categories
Find more on Migrate GUIDE Apps in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!