필터 지우기
필터 지우기

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

채택된 답변

Image Analyst
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

추가 답변 (1개)

Walter Roberson
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.

카테고리

Help CenterFile Exchange에서 Environment and Settings에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by