필터 지우기
필터 지우기

Clear axes - Except image

조회 수: 3 (최근 30일)
Jakob Sørensen
Jakob Sørensen 2012년 4월 13일
I got a GUI with several different axes, for different images. I plot some scatters and lines on these images. But it is a mess to clear, so I would like to know if there is a simple an easy way to clear an axes,something like cla(-except image), rather than testing for existing scatters and then use delete or reset.

채택된 답변

Image Analyst
Image Analyst 2012년 4월 13일
You can use findobj() like in this function that I often use:
%=====================================================================
% Erases all lines and text from the current axes.
% The current axes should be set first using the axes() command
% before this function is called, as it works from the current axes, gca.
function ClearLinesFromAxes(handles)
try
% Clear line objects.
axesHandlesToChildObjects = findobj(gca, 'Type', 'line');
if ~isempty(axesHandlesToChildObjects)
delete(axesHandlesToChildObjects);
end
% Clear text objects.
axesHandlesToChildObjects = findobj(gca, 'Type', 'text');
if ~isempty(axesHandlesToChildObjects)
delete(axesHandlesToChildObjects);
end
catch ME
message = sprintf('Error in ClearLinesFromAxes():\n%s', ME.message);
uiwait(warndlg(message));
end
return; % from ClearLinesFromAxes
Of course you can also do this:
axes(handlesToAxes);
cla reset;
imshow(yourImage);
This might also be pretty fast, though there's a possibility it may flash to white for a fraction of a second before your image redisplays.
  댓글 수: 1
Jakob Sørensen
Jakob Sørensen 2012년 4월 17일
findobj is brilliant! Though I did end up managing my problems in a slightly different way, it was this function that made it possible. Thanks!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Graphics Object Properties에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by