Question

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?

Était-ce utile?

La solution

Change

pos = sprintf('edit%', i)

to

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

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

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top