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

10 ビュー (過去 30 日間)
RGB85
RGB85 2024 年 1 月 19 日
コメント済み: Voss 2024 年 1 月 19 日
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 件のコメント
RGB85
RGB85 2024 年 1 月 19 日
Thank you for the quick response. This works great!
Voss
Voss 2024 年 1 月 19 日
You're welcome!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDevelop 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