MATLAB: Repetitive Coding for EditText in Matlab GUI

gui

hi, I'm using Matlab GUI to make UI for simple calculation. I manage to do the GUI but I wish to shorten certain part in the coding.
in order to make every EditText is empty, i use the following code:
set(handles.edit1,'string','')
...
set(handles.edit20,'string','')
from edit1 until edit20.
the same coding for me to get input value from user:
a(1)=str2double(get(handles.edit1,'string'))
until a(20) with edit20
Is there anyway to make a 'for' loop to shorten this code? Thank you in advance for every advise.

Best Answer

Hi,
yes. For example:
>> handles.edit1 = 1;
>> handles.edit2 = 2;
>> for i=1:2
handles.(['edit',num2str(i)])
end
So in your case:
for i=1:20
set(handles.(['edit',num2str(i)]),'string','')
end
And:
for i=1:20
a(i)=str2double(get(handles.(['edit',num2str(i)]),'string'))
end
Related Question