필터 지우기
필터 지우기

Remove UI Control edit box referenced with handles

조회 수: 4 (최근 30일)
Karthik KJ
Karthik KJ 2012년 6월 27일
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

채택된 답변

Walter Roberson
Walter Roberson 2012년 6월 27일
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) );
  댓글 수: 5
Karthik KJ
Karthik KJ 2012년 6월 27일
Hi Walter,
You are correct, i was initialising with higher number of entries , now i corrected it . Now this code is working. Thanks alot Walter,Sean,Jan
for i=1:20
delete(handles.sensname(i));
end
Walter Roberson
Walter Roberson 2012년 6월 27일
More efficient would be
delete(handles.sensname(1:20));
with no loop (just the one line.)

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Sean de Wolski
Sean de Wolski 2012년 6월 27일
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
Karthik KJ
Karthik KJ 2012년 6월 27일
I am not quite sure about my understanding towards handles, as i shown the example delete(u) will delete the edit box got created. But if I am deleting the edit boxes created using the gui handles, i could not able to delete the created edit boxes.
Referencing in handles, i thought handle of the uicontrol cant be deleted.
Walter Roberson
Walter Roberson 2012년 6월 27일
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by