Pregunta

In my GUI I have quite some edit fields with the names edit1, edit2, ..., editn. I try to access them in a loop.

I tried following:

for i=1:n
   pos = sprintf('edit%', i);
   content = get(handles.(pos), 'String');

with the following error message:

Reference to non-existent field 'pos'

Ideas? Anyone?

¿Fue útil?

Solución

Change

pos = sprintf('edit%', i)

to

pos = sprintf('edit%d', i)

That specifies i should be formatted as an integer when building the string.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top