App Designer: How can I use an index to increment a Value field such as editfield1.value, editfield2.value, editfield3.value, etc.?

조회 수: 37 (최근 30일)
I am trying to use a For-Loop index to populate my Edit Fields in my GUI as such:
NUM_OF_TIMING_REGISTERS = 16;
for i = 1:NUM_OF_TIMING_REGISTERS
if (tp{i} ~= 'FFFFFFFF')
app.EditField_Timing(i).Value = num2str(tp{i});
else
app.EditField_Timing(i).Value = tp{i};
end
end
My fields to populate (16 total) are called app.EditField_Timing1.Value, app.EditField_Timing2.Value, app.EditField_Timing3.Value, etc.
When trying the above code, I get the error:
Unrecognized method, property, or field 'EditField_Timing' for class 'TimingProtoCust'.
The original line, which is working correctly, is:
app.EditField_Timing1.Value = num2str(tp1);
How can I use the index value i to increment that property name so it will populate my 16 fields (app.EditField_Timing1.Value, app.EditField_Timing2.Value, app.EditField_Timing3.Value, etc.)?

채택된 답변

Matt J
Matt J 대략 4시간 전
편집: Matt J 대략 4시간 전
It would be better to use a uitable for this, or at least to use numeric EditFields instead of textual EditFields.
Regardless, you can accomplish the loop as follows:
tfields="EditField_Timing"+(1:NUM_OF_TIMING_REGISTERS);
for i = 1:NUM_OF_TIMING_REGISTERS
if ~strcmp(tp{i} , 'FFFFFFFF')
app.(tfields(i)).Value = num2str(tp{i});
else
app.(tfields(i)).Value = tp{i};
end
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by