How can I write in multiple edittexts using a 'for' loop?

2 views (last 30 days)
Hey guys, I'm creating a GUI in GUIDE and I need to write in multiple edittexts, say...100 of them. Is there a manner to write in one at a time, in a for loop, for example?
My first idea was to execute this command:
set(handles.edittext01,'string',text(1:end));
inside the loop, incrementing the expression: 'edittext01' in each iteration, but I guess it's not possible, because errors appear.
I would be grateful if someone could help me. Thank's
  1 Comment
Jan
Jan on 11 Jul 2013
"Error appears" does not allow to suggest an improvement. Better post the code and a copy of the complete error message.

Sign in to comment.

Accepted Answer

Jan
Jan on 11 Jul 2013
If you have 100 edit fields, "edit01" is a bad naming scheme. Do you see any chance to store the handles in a vector:
figure; % dummy for demonstration
handles.editH = zeros(1, 100);
for k = 1:100
col = floor((k - 1) / 10);
row = mod(k, 10);
handles.edit(k) = uicontrol('Style', 'edit', ...
'Position', [10 + col * 40, row*30, 30, 20]);
end
This is a demo only and the result will not match the figure nicely.
  1 Comment
Geraldo
Geraldo on 12 Jul 2013
Hi, Mr. Jan
I didn't posted the errors because i modified the code after them. Sorry for that.
Your answer helped me so much. The inheritance subintended in the " handles.edit(k)" is what i need: an 'array' of handles. The command set(handles.edit(k),'string','test') works good in a loop!
Thank you very much, Jan!

Sign in to comment.

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!