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

8 次查看(过去 30 天)
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)?

采纳的回答

Voss
Voss 2024-1-19
for i = 1:numel(filename)
app.(sprintf('Checkbox_%d',i)).Value = 1;
end
  3 个评论

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Develop Apps Using App Designer 的更多信息

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by