Prevent user from selecting same option

6 visualizaciones (últimos 30 días)
Anabel Garcia Hernandez
Anabel Garcia Hernandez el 2 de Feb. de 2020
Respondida: Image Analyst el 3 de Feb. de 2020
  • I am tasked with creatin a menu with 5 options and then a menu with the options left so that the user cannot choose same option twice. I know how to create the first menu but i do not know how to create the second one.

Respuestas (1)

Image Analyst
Image Analyst el 3 de Feb. de 2020
Use listdlg():
choices = {'Choice 1', 'Choice 2', 'Choice 3', 'Choice 4', 'Choice 5'}
[selectedIndex1, tf] = listdlg('ListString', choices); % Range is 1 to 5
% Remove the users choice from the list so it cannot be chosen next time.
choices(selectedIndex1) = []; % Set to null to remove it.
% Get choice from remaining items:
[selectedIndex2, tf] = listdlg('ListString', choices); % Range is 1 to 4 now
Note however that the indexes change. So for example if choice 3 was chosen and removed, choice 5, which was index 5 the first one, will be index 4 the seond time because one above it was removed.

Categorías

Más información sobre Scope Variables and Generate Names 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