MATLAB: Remove UI Control edit box referenced with handles

function handleguiguidehandlehandlesmatlab guiuicontrol

Hi,
I have created an UI control edit boxes and are created and stored in handles for eg
for i=1:20
handles.sensname(i) = uicontrol('style', 'edit','Position', [95, b-(i-1)*20, 180, 17],'BackgroundColor',[1 1 1]);
end
Now after creating this, i want to delete the ui control editboxes. What i tried is
for i=1:20
delete(handles.sensname(i));
end
But I am getting the error 'Root object may not be deleted'. i know it may be that handle values cannot be deleted, then how to solve my problem?
Appreciate any idea to solve this
Karthik

Best Answer

Is it possible that your code is not quite as shown, and that you initialize handles.sensname as an array with more elements than you store handles for? If so then the extra entries would be 0 and you would get the error you get.
Suggested replacement code (no loop needed)
delete( handles.sensname(handles.sensname > 0) );