findobj to refresh lines in a graph

2 visualizaciones (últimos 30 días)
fjnb86
fjnb86 el 18 de Oct. de 2011
Hello, I am working in a GUI and I want to add a new plot in a figure (axis) represented before.
The problem is that can not find the way to delete last function plotted for repeat the action but dont "hold on" the plots
Code for the button:
function pushbutton10_Callback(hObject, eventdata, handles)
axes(handles.axes2) %active the figure
pos=getappdata(0,'cursorposition'); %this works!
%plot lines
line1 = hline(pos(1)); this works too!
line2 = vline(pos(2));
guidata(hObject, handles);
If I click again I need to use findobj to localize line1 and line2 and delete it if they exist. Ive tried using findobj('type','line') but I couldnt find.
this psuedo code it has to be before plot:
if line1 or line2 exist then
delete(line1)
delete(line2)
end
maybe it is easier if I create a handle for this ?
thanks!

Respuesta aceptada

Daniel Shub
Daniel Shub el 19 de Oct. de 2011
Yes, it is easier if you create a handle ...
if isfield(handles, 'line1') && ishandle(handles.line1)
delete(handles.line1)
end
if isfield(handles, 'line2') && ishandle(handles.line2)
delete(handles.line2)
end
handles.line1 = hline(pos(1)); this works too!
handles.line2 = vline(pos(2));
  3 comentarios
Daniel Shub
Daniel Shub el 19 de Oct. de 2011
I don't quite understand your problem. I am guessing somehow the gui is being saved so handles has the field line1, but that line1 does nto exist. I have edited the answer to include ishandle(handles.line1). This should hopefully fix it.
fjnb86
fjnb86 el 20 de Oct. de 2011
exactly, now it works!
;)

Iniciar sesión para comentar.

Más respuestas (1)

Olaf
Olaf el 19 de Oct. de 2011
Hi A possible solution might be to use Matlab graphic handles property called 'Tag'. By default it is empty and upon creation of your lines you can assign each of your lines a unique tag, e.g. set(line1, 'Tag', 'myUniqueHLineTag'); Then, when you want to test the existence of any of these lines, you can search through the handles obtained by findobj for this tag.
Olaf

Categorías

Más información sobre Interactive Control and Callbacks en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by