How can i get value from pop up menu

14 views (last 30 days)
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

Accepted Answer

Adam Danz
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
sahin sezgin
sahin sezgin on 6 May 2019
thank you a lot you saved my life :D
It works thank you again

Sign in to comment.

More Answers (0)

Products


Release

R2015b

Community Treasure Hunt

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

Start Hunting!