Info

This question is closed. Reopen it to edit or answer.

Writing callback for gui

1 view (last 30 days)
vedesh Mohit
vedesh Mohit on 3 Jan 2020
Closed: MATLAB Answer Bot on 20 Aug 2021
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?

Answers (2)

Walter Roberson
Walter Roberson on 3 Jan 2020
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 Comment
Walter Roberson
Walter Roberson on 3 Jan 2020
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 on 3 Jan 2020
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.

Community Treasure Hunt

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

Start Hunting!