How to disable specific items from a popup menu by using a logical vector of the same length of the string of the popup menu?
3 次查看(过去 30 天)
显示 更早的评论
Hello , I need some help with a problem...
Let's say that I have a cell containing the strings I want for the popup menu, for example
t = cell(1,5);
t{1,1} = 'Hello';
t{1,2} = 'Hi';
t{1,3} = 'Welcome';
t{1,4} = 'Pleased to meet you';
t{1,5} = 'Join us';
and I also have a logical vector
logict = [false true true false true];
after setting the items in the popupmenu by executing
set(handles.popupmenu1,'String',t);
How can I disable some of the items (in this case the 1st one and the 4th one) by using the logical vector logict?
Thank you very much for the help
0 个评论
采纳的回答
Image Analyst
2016-8-28
Just do something for the ones that are true. If desired, you could do a warning for the invalid ones:
selectedItem = handles.popup1.Value;
switch selectedItem
case 1
% Do nothing.
case 2
% Do something
fprintf('You selected a valid item %d\n', selectedItem); % Whatever you want.
case 3
% Do something
msgbox('MATLAB is awesome'); % Whatever you want.
case 4
% Just warn user
message = sprintf('You selected am invalid item %d\n', selectedItem);
uiwait(warndlg(message)); % Whatever you want.
case 5
% Do something
a=10; % Whatever you want.
end
0 个评论
更多回答(1 个)
Walter Roberson
2016-8-28
It is not possible to disable individual items in a uicontrol('style', 'popup'). It is only possible to detect that one of them have been selected and to either return without doing anything or else automatically set the Value property to select something else. For example you could use the UserData property to keep a record of the last valid entry selected, and when an invalid item was selected you could set the Value property to the recorded value.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Environment and Settings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!