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

1 Ansicht (letzte 30 Tage)
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.

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 28 Feb. 2016
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 Kommentar
Arun Sharma
Arun Sharma am 29 Feb. 2016
Bearbeitet: Walter Roberson am 29 Feb. 2016
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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Graphics Performance finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by