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 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
test run
il 28 Ago 2016
Risposto: Image Analyst
il 28 Ago 2016
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 Commenti
Risposta accettata
Image Analyst
il 28 Ago 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
0 Commenti
Più risposte (1)
Walter Roberson
il 28 Ago 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.
0 Commenti
Vedere anche
Categorie
Scopri di più su Environment and Settings in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!