Programming Sliders Using Guide

6 views (last 30 days)
Caleb
Caleb on 20 Jul 2012
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.

Accepted Answer

Image Analyst
Image Analyst on 20 Jul 2012
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 Comments
Image Analyst
Image Analyst on 20 Jul 2012
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 on 23 Jul 2012
Edited: Caleb on 23 Jul 2012
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?

Sign in to comment.

More Answers (1)

Sean de Wolski
Sean de Wolski on 20 Jul 2012
Edited: Sean de Wolski on 20 Jul 2012
'visible','on',...
  9 Comments
Caleb
Caleb on 20 Jul 2012
So would I even use the slider callback function automatically generated by guide?

Sign in to comment.

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!