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

36 Ansichten (letzte 30 Tage)
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.)?

Akzeptierte Antwort

Matt J
Matt J vor etwa 4 Stunden
Bearbeitet: Matt J vor etwa 3 Stunden
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

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Produkte


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by