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

조회 수: 3 (최근 30일)
Mark Brockert
Mark Brockert 2017년 4월 3일
댓글: Mark Brockert 2017년 4월 4일
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');

답변 (1개)

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

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Graphics Objects에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by