Effacer les filtres
Effacer les filtres

Clear axes - Except image

3 vues (au cours des 30 derniers jours)
Jakob Sørensen
Jakob Sørensen le 13 Avr 2012
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.

Réponse acceptée

Image Analyst
Image Analyst le 13 Avr 2012
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 commentaire
Jakob Sørensen
Jakob Sørensen le 17 Avr 2012
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!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Graphics Object Properties dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by