Multiple check boxes to check to provide an output

44 vues (au cours des 30 derniers jours)
Muhammad Abir
Muhammad Abir le 17 Août 2020
Commenté : Noah le 3 Avr 2024 à 7:24
I have 6 checkboxes with 6 different conditions to run a query. User will select any number of check boxes (may be only 1 or may be all 6 or may be only 3 checkboxes). For example, let's say if user selects checkbox 1 and checkbox 2, then by selecting a 'search' pushbutton, the result will show one output or if user selects all checkboxes then the search will shows a different output.
  1 commentaire
Mehmed Saad
Mehmed Saad le 17 Août 2020
what have you done so far?
Show us your code

Connectez-vous pour commenter.

Réponse acceptée

Prabhanjan Mentla
Prabhanjan Mentla le 20 Août 2020
Modifié(e) : Prabhanjan Mentla le 20 Août 2020
Hi,
I assume that on selecting the combinations checkboxes the text should vary, on clicking a button.
For accessing the checkbox values, you may code something like below
function ButtonPushed(app, event)
fieldNames = fieldnames(app); % get the uicomponents
allCheckBoxNamesList = fieldNames(contains(fieldNames,'CheckBox','IgnoreCase',true)); % get the checkboxes
for i = 1:numel(allCheckBoxNamesList) % loop through all checkboxes
if app.(allCheckBoxNamesList{i}).Value == true % display all the checkboxes which are true
app.TextArea.Value = [string(app.TextArea.Value);app.(allCheckBoxNamesList{i}).Text;] % append to Text Area
end
end
You may get something like below
Hope this helps.
  2 commentaires
Noah
Noah le 3 Avr 2024 à 7:22
To get a more "generic" answer - you can use "findall" method to catch all checkboxes @ once
% --- Executes on button press in pb_search.
function pb_search_Callback(hObject, eventdata, handles)
hCheckboxes = findall(handles.output,'Style','checkbox'); % Get all checkboxes inside a container
hCheckboxes_selected = findall(hCheckboxes,'Value',1); % Get all Selected checkboxes from the above collection
strings = get(hCheckboxes_selected,'String'); % Get all the text from the Selected checkboxes
if ~isempty(strings) && iscell(strings)
strings = strjoin(strings,' ,');
end
handles.ed_search.String = strings;
Noah
Noah le 3 Avr 2024 à 7:24
of course, you can enter as the 1st input to "findall" a more specific container (a panel) that holds the relevant checkboxes...

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Entering Commands dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by