Programming Sliders Using Guide
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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.
0 comentarios
Respuesta aceptada
Image Analyst
el 20 de Jul. de 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 comentarios
Image Analyst
el 20 de Jul. de 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.
Más respuestas (1)
Sean de Wolski
el 20 de Jul. de 2012
Editada: Sean de Wolski
el 20 de Jul. de 2012
'visible','on',...
9 comentarios
Ver también
Categorías
Más información sobre Interactive Control and Callbacks en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!