How can I plot in real time where I have a circle be the current position, and I also have a line of every past position?

조회 수: 11 (최근 30일)
I'm plotting the trajectory of a quadrotor in a simulation I made. I have the 3D position of the quadrotor at every time step (from 0 to 100,000). Is there a way I can plot the quadrotors position in real time, in order to make a nice gif? I know hwo to do it with a single line, but I want a circle to represent the current positon of the quadrotor, but also a line of its past trajectory.

답변 (1개)

Adam Danz
Adam Danz 2019년 6월 19일
편집: Adam Danz 2019년 6월 24일
Option 1
Here's a demo to run that plots the progression of a curve as a line with a circle marker at the current coordinate. After producing the empty plot, it iteratively updates the XData and YData of each line object and refreshes the plot using drawnow(). You mentioned you had 100k data points so instead of updating on each iteration you may want to up date every 100 iterations or so after applying this to your real time data.
% Create fake data
time = 0:0.1:20;
data = sin(time);
% set up plot
figure();
lh = plot(nan, nan, 'b-');
hold on
mh = plot(NaN,NaN,'bo');
xlim([time(1),time(end)])
ylim([min(data),max(data)])
% Loop through data and update coordinates
for i = 1:numel(time)
lh.XData = time(1:i);
lh.YData = data(1:i);
mh.XData = time(i);
mh.YData = data(i);
drawnow();
end
Here's how to control how often the plot refreshes
iterationUpdate = 1 : 1000 : 100000; % every 1000 frames
% Loop through data and update coordinates
for i = 1:100000
...
if ismember(i,iterationUpdate)
drawnow();
end
end
Option 2
You can use a comet plot.
comet(time, data);

카테고리

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

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by