سؤال

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?

هل كانت مفيدة؟

المحلول

Change

pos = sprintf('edit%', i)

to

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

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

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top