Remove UI Control edit box referenced with handles
Show older comments
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
Accepted Answer
More Answers (1)
Sean de Wolski
on 27 Jun 2012
That means that handles.sensname(i) is returning a 0, the handle to the root object.
It it kind of hard to tell you what is broken with it, but perhaps you could just check for zeros first.
for ii = 1:10;
if logical(handles.sensname(ii))
delete(handles.sensname(ii));
end
end
More Note also that if I run those two lines of code back2back I don't get the error:
figure;
for i=1:20
handles.sensname(i) = uicontrol('style', 'edit','Position', [95, pi-(i-1)*20, 180, 17],'BackgroundColor',[1 1 1]);
end
for i=1:20
delete(handles.sensname(i));
end
5 Comments
Karthik KJ
on 27 Jun 2012
Jan
on 27 Jun 2012
Or: if handles.sensname(ii) ~= 0
Jan
on 27 Jun 2012
@Karthik: What did not work and which error message do you get?
The problem is *not* related to the fact, that the handle of the UICONTROL is stored in a struct called "handles". Therefore I do not understand, what "referencing in handles" means and how it could affect the error.
Karthik KJ
on 27 Jun 2012
Walter Roberson
on 27 Jun 2012
Any handle graphics object can be deleted _except_ for the root object (0). This includes uicontrol() and text() and plots and surf() and so on.
Categories
Find more on Creating, Deleting, and Querying Graphics Objects in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!