Programming Sliders Using Guide

3 次查看(过去 30 天)
I'm trying to program sliders using guide, and I'm not sure how this will work.
First off, I can't get the slider to become visible when I call a certain function. What I am wanting to do is to allow multiple sliders to become visible for the purpose of iterating through to find the optimal code.
%popupmenu_contrast
str = get(hObject, 'String');
val = get(hObject, 'Value');
% set current contrast operation to the user-selected
switch str{val};
case 'imadjust';
handles.current_contrast = @imadjust;
set(handles.slider1, ...
'Visible', {On},...
'Min', 0, ...
'Max', 1, ...
'Value', 0,...
'SliderStep', [0.05, 0.01]);
set(handles.text_1, 'string', 'low_in')
case 'histeq';
handles.current_contrast = @histeq;
case 'adapthisteq';
handles.current_contrast = @adapthisteq;
case 'imcomplement';
handles.current_contrast = @imcomplement;
end
handles.image2 = handles.current_contrast(handles.image);
imshow(handles.image2, 'Parent', handles.axes2);
% save handles structure
guidata(hObject, handles);
And I'm wondering how I will pass the information from the slider callback function back into this function to properly perform the desired operation.

采纳的回答

Image Analyst
Image Analyst 2012-7-20
It sound like you have a slider where the user can set some kind of parameter. And the parameter means different things depending on what pop-up item is selected. Is that right? So what I'd do is to have a separate function called AdjustImageContrast(), which would take handles as an input argument. Then in the callback for the popup, I'd check the selected item, and if it's "imadjust" I'd first initialize the slider min, max, and value properties since these might be different depending on what popup item was selected. Then after setting up the slider I'd call AdjustImageContrast(handles). Inside AdjustImageContrast, you'd get the slider value via get(handles.slider1, 'value') and do the contrast adjustment code.
Now, what if the user slides the slider instead of selecting a popup item? In that case, you'd do essentially the same thing as the popup callback - check which popup was selected EXCEPT that you don't need to reinitialize the slider since you need to take the current value the user set it to. So if the "imadjust" was already selected, you'd skip the slider initialization and immediately call AdjustImageContrast(handles).
I hope you followed all that.
  3 个评论
Image Analyst
Image Analyst 2012-7-20
I understand. What I said will work. handles is practically a global variable but not quite - that's why you have to pass it into your own functions like AdjustImageContrast() if you want them to access controls like sliders and popup lists. You can use the same 5 sliders for all tasks, just initialize them, or hide them, depending on what popup item was selected.
Caleb
Caleb 2012-7-23
编辑:Caleb 2012-7-23
When using AdjustImageContrast() would I write if-then statements to say the following:
given functions a,b,c,d. User selects (a) and I write an if-then to recognize their pick and then apply the code within AdjustImageContrast(). I'll have four different codes for the four different functions that the user can choose?
Would I even need to code the slider movement functions?

请先登录,再进行评论。

更多回答(1 个)

Sean de Wolski
Sean de Wolski 2012-7-20
编辑:Sean de Wolski 2012-7-20
'visible','on',...
  9 个评论
Caleb
Caleb 2012-7-20
So would I even use the slider callback function automatically generated by guide?

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Interactive Control and Callbacks 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by