How to create a drop down list with fixed title?

조회 수: 2 (최근 30일)
Nipurn Gulgulia
Nipurn Gulgulia 2018년 2월 14일
댓글: Rik 2018년 2월 15일
I want a drop box with title 'Math' under which basic mathematical operations will be there-
BasicOperation = uicontrol(parent, 'Style', 'popup', 'Units', 'normalized', 'ToolTipString', 'Add/Subtract', 'String',{' = ',' + ',' - ',' * ',' / '} );
Like in this image - Title 'MATLAB Central' under which some options are there!
Thanks!
  댓글 수: 2
Adam
Adam 2018년 2월 14일
A dropdown list in a panel with a title, or simply with a text box above it would be the simplest option.
Nipurn Gulgulia
Nipurn Gulgulia 2018년 2월 15일
편집: Nipurn Gulgulia 2018년 2월 15일
@Adam I am doing it in panel only, but i have 5-6 different drop down button. I can't give a single title. Is there any other type of button which i can use?

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

채택된 답변

Rik
Rik 2018년 2월 14일
The code below stores the chosen option in handles.BasicOperationString and resets the value back to the first option. You need to add something somewhere to control for the case that the user selects the first option (i.e. the explanatory text).
handles.BasicOperation = uicontrol(...
'Parent',parent,...
'Style', 'popup',...
'Units', 'normalized',...
'ToolTipString', 'Add/Subtract',...
'String',{'Basic operations',' = ',' + ',' - ',' * ',' / '},...
'Callback',@(hObject,eventdata) BasicOperationCallback(hObject,eventdata,guidata(hObject)));
function BasicOperationCallback(hObject,eventdata,handles)%#ok
val=get(hObject,'Value');
str=get(hObject,'String');
handles.BasicOperationString=str{val};
guidata(hObject,handles)%update handle struct
set(hObject,'Value',1);%reset to text
end
  댓글 수: 5
Nipurn Gulgulia
Nipurn Gulgulia 2018년 2월 15일
편집: Nipurn Gulgulia 2018년 2월 15일
Thanks for your suggestions, I tried to run your code but i am getting error "Undefined function 'BasicOperationCallback' for input arguments of type 'double'."
Rik
Rik 2018년 2월 15일
How did you save it? Because I see no reason why this would be the case.

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

추가 답변 (0개)

카테고리

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