Give multiple choice for Popup menu by code.
3 views (last 30 days)
Show older comments
Hi every one , i have multiple features and multiple values for each. for example i have : name , age , sex , eye color , ... etc as a features and i have for every one multiple objects: for age i have 25,26,43,65,15,34,87,...etc therefore i suppose to work on multiple popup menu for every features there is a popup menu and when i run the code the use select only one value. My question is : Is popup is my best choice for that problem? if yes, how can i set the values in every popup menu automatically from matrix or from file (i dont need to select it manually because there is handred of values)
0 Comments
Accepted Answer
Walter Roberson
on 26 Apr 2013
Edited: Walter Roberson
on 26 Apr 2013
Popup is fine.
In order to set a popup menu's setting according to a matrix or file, you need to take the external representation of the value (e.g., 'blue' for eyes) and find it in the list of possible values. Take the index of the desired value down the list, and set() the handle's 'Value' parameter to that index.
Sample:
eyecolors = {'Unknown', 'blue', 'green', 'grey', 'brown'};
h = uicontrol('Style','pop', 'String', eyecolors);
...
thiseyecolor = 'grey';
[tf, idx] = ismember(thiseyecolor, eyecolors);
if tf
set(h, 'Value', idx)
else
warning(sprintf('What? Eye color is "%s" ??', thiseyecolor));
set(h, 'Value', 1);
end
4 Comments
Walter Roberson
on 26 Apr 2013
menuchoices = {{'Unknown', 'blue', 'green', 'grey', 'brown'},
{'Unknown', 'male', 'female', 'other'},
{'Unknown', '25', '26', '43', '65', '15', '34', '87'}};
nummenu = length(menuchoices);
menuhandles = zeros(nummenu, 1);
for K = 1 : nummenu
menuhandles(K) = uicontrol('Style', 'pop', 'String', menuchoices{K}, 'Value', 1, 'Units', 'norm', 'Position', [0, (K-1)/nummenu, 1/10, 1/(nummenu+1)]);
end
Now you can iterate over the menuhandles, doing comparisons to menuchoices{K}
More Answers (0)
See Also
Categories
Find more on Structures 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!