How can I delete a plotted line in an axes GUI?

1 visualización (últimos 30 días)
Mark Brockert
Mark Brockert el 3 de Abr. de 2017
Comentada: Mark Brockert el 4 de Abr. de 2017
I am trying to create a GUI that allows the user to add forces in polar or rectangular format and displays these forces in a graph, calculates the resultant force for every force that has been entered and then displays the resultant force in the graph. I am having difficulty when I add a new force, the previous resultants remain plotted when I would like the resultant to be replaced as it is recalculated every time a new force is added.
axes(handles.graph);
plot([0 x(n)],[0 y(n)],'r--'); % plots each entered force
grid on;
hold on;
axis([-10 10 -10 10]);
final = plot([0 x_res],[0 y_res],'b-'); % plots resultant
legend(final,'Resultant');

Respuestas (1)

Jan
Jan el 3 de Abr. de 2017
Store the handle of the line and delete formerly existing lines:
delete(handles.final);
handles.final = plot([0 x_res],[0 y_res],'b-');
guidata(hObject, handles);
Set handles.final to [] in the OpeningFcn.
  1 comentario
Mark Brockert
Mark Brockert el 4 de Abr. de 2017
Creates an error in the OpeningFcn saying
Reference to non-existent field 'final'.

Iniciar sesión para comentar.

Categorías

Más información sobre Graphics Objects en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by