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

3 Ansichten (letzte 30 Tage)
Mark Brockert
Mark Brockert am 3 Apr. 2017
Kommentiert: Mark Brockert am 4 Apr. 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');

Antworten (1)

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

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Graphics Objects finden Sie in Help 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