Hello everyone,
I have a simple question: is it possible to delete all lines (I mean, using the function line()) and not the rest of plots in an axes gui?
I am making a cursor and I am using the function line() to draw it. I have a little problem in my code, so I thought delete all my lines and then draw the lines that I need.
I can't use in my case: if ishandle(cursor) delete(cursor) end
Any advice?
Thank you in advance

 Akzeptierte Antwort

Image Analyst
Image Analyst am 10 Feb. 2016

1 Stimme

You have to keep track of the handles to the lines as you create them, because I think curves made by plot() might also be identified as lines by findobj(). If it's in a loop, then
for k = 1 : whatever
hLines(k) = line(.....
end
% Delete them
delete(hLines);
Or run this demo:
t=linspace(0,6*pi, 1000);
f = 8 * exp(-0.25*t).*sin(t - 2);
plot(t, f);
grid on;
hold on;
% Make lines.
hLines(1)=line([2,8], [3,-4], 'Color', 'r', 'LineWidth', 2)
hLines(2)=line([10,16], [-2,4], 'Color', 'r', 'LineWidth', 2)
% Clear lines.
uiwait(msgbox('Click OK to clear the lines'));
delete(hLines);

3 Kommentare

It was a great idea and it works, however I have a little problem: I can't use only delete(), before I must verify if my variable cursors exist. I've tried:
if ishandle(cursors)
delete(cursors)
end
However, it doesn't run my loop. Any other alternative?
Thank you for your prompt reply.
Image Analyst
Image Analyst am 11 Feb. 2016
Bearbeitet: Image Analyst am 14 Feb. 2016
I don't know why you call your line handles "cursors" or why you need to check if they're handles or not. You know they must be or you never would have assigned them.
Here's another function I've used:
%========================================================
% Erases all lines from the axes control with handle "h".
function ClearLinesFromAxes(h)
%fprintf('In ClearLinesFromAxes...\n');
axesHandlesToChildObjects = findobj(h, 'Type', 'line');
if ~isempty(axesHandlesToChildObjects)
delete(axesHandlesToChildObjects);
end
%fprintf('Leaving ClearLinesFromAxes.\n');
return; % from ClearLinesFromAxes
pem.cristina
pem.cristina am 14 Feb. 2016
It was exactly what I needed! It has been really helpful
Thanks again.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Specifying Target for Graphics Output finden Sie in Hilfe-Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by