App Designer: How can I use an index to increment a Value field such as editfield1.value, editfield2.value, editfield3.value, etc.?
37 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Scotty Mac
el 4 de Nov. de 2025 a las 16:59
Comentada: Stephen23
hace alrededor de 19 horas
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 comentario
Stephen23
hace alrededor de 2 horas
Another option would be to use an array of graphics handles and some basic indexing:
Respuesta aceptada
Matt J
hace alrededor de 5 horas
Editada: Matt J
hace alrededor de 4 horas
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
1 comentario
Más respuestas (0)
Ver también
Categorías
Más información sobre Loops and Conditional Statements en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!