Clear axes - Except image

3 次查看(过去 30 天)
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