필터 지우기
필터 지우기

Ho to delete the image from the axes?

조회 수: 9 (최근 30일)
Animesh
Animesh 2013년 12월 23일
댓글: Image Analyst 2014년 2월 4일
I want to remove the image from the axes(say axes1) upon clicking a button keeping the axes intact.
I have tried using
children=get(handles.axes1, 'children');
delete(children);
and other things but it completely removes the axes.
Can anyone help??
Thanx in advance

채택된 답변

Image Analyst
Image Analyst 2013년 12월 23일
편집: Image Analyst 2013년 12월 23일
You need to find the image in the axes with findobj() and then delete it. Like this:
axesHandlesToChildObjects = findobj(h, 'Type', 'image');
if ~isempty(axesHandlesToChildObjects)
delete(axesHandlesToChildObjects);
end
You can't just call cla() or it will delete everything such as text, arrows, overlays, or other annotation you added. Try this full demo:
function test3
% Display an image.
imshow('moon.tif');
axis on;
% Add some text.
text(100,250, 'Moon', 'FontSize', 30, 'Color', 'r');
promptMessage = sprintf('Do you want to clear the image only?');
titleBarCaption = 'Continue?';
button = questdlg(promptMessage, titleBarCaption, 'OK', 'Cancel', 'OK');
if strcmpi(button, 'OK')
% Get rid of image from current axes, but leave text.
ClearImagesFromAxes(gca)
end
%=====================================================================
% Erases all images from the axes.
function ClearImagesFromAxes(h)
axesHandlesToChildObjects = findobj(h, 'Type', 'image');
if ~isempty(axesHandlesToChildObjects)
delete(axesHandlesToChildObjects);
end
return; % from ClearImagesFromAxes
  댓글 수: 3
Image Analyst
Image Analyst 2014년 1월 8일
Try "axis on" for the second axis too. Your axis on only applied to the current axes, which presumably was your axes1, so it never got turned on for axes2.
Animesh
Animesh 2014년 1월 9일
Thanks sir. It worked by adding axes(handles.axes2);axis on

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

추가 답변 (1개)

Azzi Abdelmalek
Azzi Abdelmalek 2013년 12월 23일
Try
cla(handles.axes1)
  댓글 수: 2
Jean Bilheux
Jean Bilheux 2014년 2월 3일
I didn't think about that one ('cla') and it worked great for me !
Image Analyst
Image Analyst 2014년 2월 4일
But it clears more than just the image (which is what the original poster wanted to restrict it to). If you want to clear everything, then that's fine - it will work.

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

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by