Extracting the value of a slider
22 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(5 个)
Doug Hull
2011-6-14
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 个评论
Matt Tearle
2011-6-14
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 个评论
Oscar Machuca
2013-4-2
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Graphics Object Properties 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!