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.)?
댓글 수: 1
Stephen23
대략 6시간 전
Another option would be to use an array of graphics handles and some basic indexing:
채택된 답변
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 Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!