Output argument (and possibly others) not assigned value in the execution with "choosedialog2" function

45 visualizaciones (últimos 30 días)
The code worked for all cell number selections except the first index of 1
Not sure where to correct and run the code?
specific_index = choosedialog2(num2cell(1:20))
  1 comentario
Walter Roberson
Walter Roberson el 22 de Nov. de 2023
dbtype choosedialog2
1 function [val] = choosedialog2 (menuitems) 2 3 d = dialog('Position',[300 300 250 150],'Name','Select One'); 4 5 txt = uicontrol('Parent',d,... 6 'Style','text',... 7 'Position',[20 80 210 40],... 8 'String','Select a number of the test data to delete'); 9 10 obj = uicontrol('Parent',d,... 11 'Style','popup',... 12 'Position',[75 70 100 25],... 13 'String',menuitems,... 14 'Callback',@popupCallback); 15 16 btn = uicontrol('Parent',d,... 17 'Position',[89 20 70 25],... 18 'String','Close',... 19 'Callback','delete(gcf)'); 20 21 22 23 % Wait for d to close before running to completion 24 uiwait(d); 25 26 27 function popupCallback ( obj, event ) 28 str = get ( obj, 'string' ); 29 val = get ( obj, 'value' ); 30 31 end 32 33 end 34 %%

Iniciar sesión para comentar.

Respuesta aceptada

Walter Roberson
Walter Roberson el 22 de Nov. de 2023
uicontrol() style popup only triggers the callback when the selection changes
When you create a uicontrol popup, the default selection Value is 1 -- first item already selected.
What you typically end up doing is adding a header item such as 'Select Item' as the first String, so that the user has to change selection in order to select "1" .
If you do that remember that the entries are now offset by 1 -- the entry for "1" is at Value 2, the entry for "2" is at Value 3, and so on.
And remember that your processing code has to handle the possibility that later the user will chose to switch back to the header.
... And remember that this does not solve the problem of the user wanting to select the same entry twice in a row -- not unless you reset the Value to 1 (the header)

Más respuestas (0)

Categorías

Más información sobre Migrate GUIDE Apps en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by