Clear axes - Except image
2 次查看(过去 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.
0 个评论
采纳的回答
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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Migrate GUIDE Apps 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!