How can i get value from pop up menu
14 views (last 30 days)
Show older comments
Hello everyone
i want to get values from popup menu. And then i want to set this values for plot command. How can i do this
N7=num2strget(handles.popupmenu2,'String')
plot(N1,N2,N7);
function popupmenu2_Callback(hObject, eventdata, handles)
switch get(handles.popupmenu,'Value')
if (a==1)
set(handles.popupmenu2,'Value','o');
elseif (a==2)
set(handles.popupmenu2,'Value','+');
elseif (a==3)
set(handles.popupmenu2,'Value','s');
elseif (a==4)
set(handles.popupmenu2,'Value','x');
elseif (a==5)
set(handles.popupmenu2,'Value','-');
elseif (a==6)
set(handles.popupmenu2,'Value','*');
elseif (a==7)
set(handles.popupmenu2,'Value','d');
end
0 Comments
Accepted Answer
Adam Danz
on 6 May 2019
Edited: Adam Danz
on 6 May 2019
The "value" property of a popup menu indicates the user's selection by returning the index value (an integer). The "string" property lists the options. To identify the string selected, you must use the index value to access the cell array of strings. Here's a functional example.
%Create quick popup menu
h = uicontrol('style','popup','string',{'Lancaster', 'Cincinnati', 'Sofia', 'Rochester'});
%Let's say I selected the 2nd option: "Cincinnati"
h.Value --> 2
h.String --> {'Lancaster', 'Cincinnati', 'Sofia', 'Rochester'}.'
h.String{h.Value} --> 'Cincinnati'
To adapt that to your needs,
selectedString = h.String{h.Value};
switch selectedString
case 'Lancaster'
% do something
case 'Cincinnati'
% do something
case 'Sofia'
% do something
case 'Rochester'
% do something
otherwise
error('Did not recognized string ''%s''', selectedString)
end
6 Comments
More Answers (0)
See Also
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!