Info

この質問は閉じられています。 編集または回答するには再度開いてください。

Writing callback for gui

2 ビュー (過去 30 日間)
vedesh Mohit
vedesh Mohit 2020 年 1 月 3 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
hey,
I have to create a GUI that allows the user to construct a logic circuit from a menu using NOT, AND and OR gates. The gates are required to be placed in a static position in the construction window. How do I go about writing a callback for the pushbutton that when the user clicks the button, a popup menu appears to ask the user which section to place the gate?

回答 (2 件)

Walter Roberson
Walter Roberson 2020 年 1 月 3 日
valid_sections = {'A3', 'B17', 'Thorax', 'Trailing L2 point'};
choice = menu('Choose a section to place into', valid_sections);
if choice == 0
user did not select anything
else
section_name = valid_sections{choice};
now do something based upon section_name
end
  1 件のコメント
Walter Roberson
Walter Roberson 2020 年 1 月 3 日
You can improve the above by something like,
if ~isfield(handles, 'used_sections')
handles.used_sections = {};
end
valid_sections = {'A3', 'B17', 'Thorax', 'Trailing L2 point'};
available_sections = setdiff(valid_sections, handles.used_sections);
choice = menu('Choose a section to place into', available_sections);
if choice == 0
user did not select anything
else
section_name = valid_sections{choice};
now do something based upon section_name
%update list of used sections
handles.used_sections{end+1} = section_name;
guidata(hObject, handles);
end

Image Analyst
Image Analyst 2020 年 1 月 3 日
Are you using GUIDE or App Designer? Either way, the source code will have a callback for the pushbutton. If using GUIDE, right click on the button and say "view callback", then, in the callback function, you can use either questdlg() or menu() to get the user's choice of NOT, AND, or OR.
  1 件のコメント
vedesh Mohit
vedesh Mohit 2020 年 1 月 3 日
yes i am using guide

Community Treasure Hunt

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

Start Hunting!

Translated by