필터 지우기
필터 지우기

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

조회 수: 100 (최근 30일)
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
Walter Roberson
Walter Roberson 2023년 11월 22일
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 %%

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2023년 11월 22일
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)

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by