I have over a 100 checkboxes. I want to check them with one line of code in Appdesigner the same way that I did in Matlab 2013.. However the same line of code does not work in Appdesigner. Here is the code from 2013 Matlab

19 views (last 30 days)
set(findobj('Style','checkbox','-regexp','Tag','checkbox'),'Value',1)

Accepted Answer

Luna
Luna on 3 Jan 2019
I have tried this, created 5 checkboxes and a button for check all.
You can get the struct fieldnames and filter by its name CheckBox.
It is not an efficient way manually assign Tags for each checkbox so left the names as Matlab creates automatically.
classdef app1 < matlab.apps.AppBase
% Properties that correspond to app components
properties (Access = public)
UIFigure matlab.ui.Figure
CheckBox matlab.ui.control.CheckBox
CheckBox2 matlab.ui.control.CheckBox
CheckBox3 matlab.ui.control.CheckBox
CheckBox4 matlab.ui.control.CheckBox
CheckBox5 matlab.ui.control.CheckBox
checkallButton matlab.ui.control.Button
end
methods (Access = private)
% Button pushed function: checkallButton
function checkallButtonPushed(app, event)
fieldNames = fieldnames(app); % gets the name list for all uicomponents as cell array
allCheckBoxNamesList = fieldNames(contains(fieldNames,'CheckBox','IgnoreCase',false)); % gets only the names contains "CheckBox" specifically.
for i = 1:numel(allCheckBoxNamesList) % a for loop for set all checkbox components' values as true
app.(allCheckBoxNamesList{i}).Value = true; % dynamic naming to reach elements under my app.
end
end
end

More Answers (0)

Categories

Find more on Develop Apps Using App Designer in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!