Borrar filtros
Borrar filtros

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 visualizaciones (últimos 30 días)
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

Respuesta aceptada

Image Analyst
Image Analyst el 28 de Ag. de 2016
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

Más respuestas (1)

Walter Roberson
Walter Roberson el 28 de Ag. de 2016
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.

Categorías

Más información sobre Environment and Settings en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by