Is there a way to iterate through numbered UI components in app designer?

10 views (last 30 days)
I have the following code in an appdesigner app that allows users to select multiple files (up to 10), read them, plot data on a UI axis, and report values in a UI table. All of the selected files will be included in the table and plot, but the user needs the option to exclude some of the data from statistical analysis that is performed in a different callback. I've accomplished this by using check boxes to the left of each row of the table (named app.CheckBox_# where # = 1-10).
for i = 1:numel(filename)
app.data.suite(i).spec = readcell([pathname, filename{i}]);
% Read in force and displacement data
for k = 2:length(app.data.suite(i).spec)
app.data.AxDisp(i).vec(k-1) = app.data.suite(i).spec{k,3};
app.data.AxForce(i).vec(k-1) = app.data.suite(i).spec{k,2};
end
%Plot each data set
plot(app.UIAxes2, app.data.AxDisp(i).vec,app.data.AxForce(i).vec,'LineWidth',1);
%Calculate parameters
app.data.maxload(i) = max(app.data.AxForce(i).vec); %lbs
app.data.thickness(i) = cell2mat(app.data.suite(i).spec(4,8));
app.data.diameter(i) = cell2mat(app.data.suite(i).spec(3,8));
%Determine strength
switch app.PlatenTypeDropDown.Value
case 'Curved'
app.data.strength(i) = (1.272*app.data.maxload(i))/(pi*app.data.diameter(i)*app.data.thickness(i));
case 'Flat'
app.data.strength(i) = (2*app.data.maxload(i))/(pi*app.data.diameter(i)*app.data.thickness(i));
end
%Populate UI table
app.UITable.Data(i,2) = num2cell(app.data.maxload(i));
app.UITable.Data(i,3) = num2cell(app.data.strength(i));
end
I would like to add a section in the above loop that would toggle on each numbered check box based on the same numel(filename) condition as shown below.
for i = 1:numel(filename)
app.Checkbox_(i).Value = 1
end
Is there a way to iterate over numbered checkboxes (and other numbered UI components)?

Accepted Answer

Voss
Voss on 19 Jan 2024
for i = 1:numel(filename)
app.(sprintf('Checkbox_%d',i)).Value = 1;
end
  3 Comments

Sign in to comment.

More Answers (0)

Categories

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

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!