Programming Sliders Using Guide

조회 수: 5 (최근 30일)
Caleb
Caleb 2012년 7월 20일
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
Sean de Wolski
Sean de Wolski 2012년 7월 20일
I wouldn't.
Caleb
Caleb 2012년 7월 20일
So would I even use the slider callback function automatically generated by guide?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by