Programming Sliders Using Guide
Show older comments
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
More Answers (1)
Sean de Wolski
on 20 Jul 2012
Edited: Sean de Wolski
on 20 Jul 2012
'visible','on',...
9 Comments
Caleb
on 20 Jul 2012
Sean de Wolski
on 20 Jul 2012
Its value? Are you calling the image contrast callback from within the slider callback? I do not have a good feel for your GUI.
Caleb
on 20 Jul 2012
Sean de Wolski
on 20 Jul 2012
Then the easiest and most readable way to do this is to call those callbacks from the end of the slider's callback.
Another way would be to add a listener for 'PostSet' events on the slider but that is sloppy and hard to follow.
Caleb
on 20 Jul 2012
Sean de Wolski
on 20 Jul 2012
No. Just setting the slider value to a new value will not evaluate its callback. It has to be a user interaction to do this.
Instead, adjust the value, and then call the slider callback from within the adjust contrast callback (feed it the necessary inputs etc.).
E.g:
function adjustcontrastcallback(hObject,eventdata,handles)
set(handles.slider,'value',pi)
slider_callback(handles.slider,[],handles)
Caleb
on 20 Jul 2012
Sean de Wolski
on 20 Jul 2012
I wouldn't.
Caleb
on 20 Jul 2012
Categories
Find more on Creating, Deleting, and Querying Graphics Objects in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!