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

18 visualizaciones (últimos 30 días)
set(findobj('Style','checkbox','-regexp','Tag','checkbox'),'Value',1)

Respuesta aceptada

Luna
Luna el 3 de En. de 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

Más respuestas (0)

Categorías

Más información sobre Develop Apps Using App Designer en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by