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

1 view (last 30 days)
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');

Answers (1)

Jan
Jan on 3 Apr 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 Comment
Mark Brockert
Mark Brockert on 4 Apr 2017
Creates an error in the OpeningFcn saying
Reference to non-existent field 'final'.

Sign in to comment.

Categories

Find more on Graphics Objects in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!