How to create a drop down list with fixed title?

2 Ansichten (letzte 30 Tage)
Nipurn Gulgulia
Nipurn Gulgulia am 14 Feb. 2018
Kommentiert: Rik am 15 Feb. 2018
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 Kommentare
Adam
Adam am 14 Feb. 2018
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 am 15 Feb. 2018
Bearbeitet: Nipurn Gulgulia am 15 Feb. 2018
@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?

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Rik
Rik am 14 Feb. 2018
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 Kommentare
Nipurn Gulgulia
Nipurn Gulgulia am 15 Feb. 2018
Bearbeitet: Nipurn Gulgulia am 15 Feb. 2018
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 am 15 Feb. 2018
How did you save it? Because I see no reason why this would be the case.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Migrate GUIDE Apps finden Sie in Help Center und File Exchange

Tags

Noch keine Tags eingegeben.

Community Treasure Hunt

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

Start Hunting!

Translated by