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 Center および File ExchangeGraphics Performance についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by