필터 지우기
필터 지우기

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

조회 수: 8 (최근 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!

댓글을 달려면 로그인하십시오.

추가 답변 (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