Info

Cette question est clôturée. Rouvrir pour modifier ou répondre.

Writing callback for gui

2 vues (au cours des 30 derniers jours)
vedesh Mohit
vedesh Mohit le 3 Jan 2020
Clôturé : MATLAB Answer Bot le 20 Août 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?

Réponses (2)

Walter Roberson
Walter Roberson le 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 commentaire
Walter Roberson
Walter Roberson le 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 le 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.
  1 commentaire
vedesh Mohit
vedesh Mohit le 3 Jan 2020
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