Want to plot in my existing axes of GUI and then delete it.

조회 수: 1 (최근 30일)
Arun Sharma
Arun Sharma 2016년 2월 28일
편집: Walter Roberson 2016년 2월 29일
Hello Everyone
I am trying to build a GUI that will display data coming from serial port. Posting whole code will create confusion, so i am posting the relevant part.
I created a axes in GUI and then update it, based on the data coming from the serial port it has to be updated again and then i have to delete some part.
Here is the code
set(handles.plot_vector(Angle),'XData',[x0,x]);
set(handles.plot_vector(Angle),'YData',[y0,y]);
% m = handles.plot_vector(Angle);
% set(m,'XData',[x0,0],'Color','Red','LineWidth',3);
% set(m,'YData',[y0,0],'Color','Red','LineWidth',3);
axes(handles.axes1)
m = plot([0,x0],[0,y0],'r','LineWidth',3);
drawnow
delete(m);
Actually i have to draw a straight line based on the Angle value coming from the Serial Port, so i used the following command and then have to delete this.
m = plot([0,x0],[0,y0],'r','LineWidth',3);
But the above line opens a new figure, but i have to do this thing on same axes.
I tried this
% m = handles.plot_vector(Angle);
% set(m,'XData',[x0,0],'Color','Red','LineWidth',3);
% set(m,'YData',[y0,0],'Color','Red','LineWidth',3);
This plots the line on axes but i don't know how to delete only this part.
Actually i am trying to display UltraSonic data in the form of radar in MATLAB GUI, So it will look like scanning, but stuck with this, hope someone helps me.

채택된 답변

Walter Roberson
Walter Roberson 2016년 2월 28일
m = plot(handles.axes1, [0,x0], [0,y0], 'r', 'LineWidth', 3);
drawnow
delete(m);
Since you are doing this repeatedly it would be better to create a line at the beginning and update it as you go along.
m = plot(handles.axes1, nan, nan, 'r', 'LineWidth', 3);
while true
...
set(m, 'XData', [0 x0], 'YData', [0 y0]);
drawnow();
...
end
delete(m); %when we are done with drawing lines
  댓글 수: 1
Arun Sharma
Arun Sharma 2016년 2월 29일
편집: Walter Roberson 2016년 2월 29일
Thanks.
Actually i was easy, i just need this.
set(handles.plot_vector(Angle),'XData',[x0,x]);
set(handles.plot_vector(Angle),'YData',[y0,y]);
scanner = plot(handles.axes1,[0,x0],[0,y0],'r','LineWidth',3);
drawnow
delete(scanner);
Actually plot(handles.axes1,...) works for me.
Thanks for your help.

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

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by