Return popupmenu selection in MATLAB using one line of code
Posted
by Doresoom
on Stack Overflow
See other posts from Stack Overflow
or by Doresoom
Published on 2010-05-03T17:48:06Z
Indexed on
2010/05/03
18:08 UTC
Read the original article
Hit count: 228
I have a GUI which uses a selection from a popupmenu in another callback. Is there a way to return the selected value of the popupmenu in only one line without creating any temporary variables? I've tried several solutions, but I've only managed two lines with one temporary variable:
Three lines:
list=get(handles.popupmenu1,'String');
val=get(handles.popupmenu1,'Value');
str=list{val};
Two lines:
temp=get(handles.popupmenu1,{'String','Value'});
str=temp{1}{temp{2}};
Can anyone shave it down to one?
PS, It's a dynamic menu, so I can't just use get(handles.popupmenu1,'Value')
and ignore the string component altogether.)
© Stack Overflow or respective owner