How can i get value from pop up menu

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

 Respuesta aceptada

Adam Danz
Adam Danz el 6 de Mayo de 2019
Editada: Adam Danz el 6 de Mayo de 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 comentarios

sahin sezgin
sahin sezgin el 6 de Mayo de 2019
thank you
Adam Danz
Adam Danz el 6 de Mayo de 2019
Editada: Adam Danz el 6 de Mayo de 2019
If you have any questions about this, please let me know here in the comments section.
sahin sezgin
sahin sezgin el 6 de Mayo de 2019
Adsız.png
i can plot this but i can't change data plot style with plot button this is actually my problem and i couldn't do it with your codes
There are several approaches but I'll continue what I started....
selectedString = h.String{h.Value};
switch selectedString
case 'Circle'
markerSym = 'o';
case 'Plus'
markerSym = '+'
case 'Square'
markerSym = 's'
% You get the point.. add the other cases
otherwise
error('Did not recognized marker type ''%s''', selectedString)
end
plot(x,y,'-o', 'Marker', markerSym)
sahin sezgin
sahin sezgin el 6 de Mayo de 2019
thank you a lot you saved my life :D
It works thank you again
Adam Danz
Adam Danz el 6 de Mayo de 2019
Glad I could help!

Iniciar sesión para comentar.

Más respuestas (0)

Productos

Versión

R2015b

Preguntada:

el 6 de Mayo de 2019

Comentada:

el 6 de Mayo de 2019

Community Treasure Hunt

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

Start Hunting!

Translated by