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 visualizaciones (últimos 30 días)
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.

Respuestas (1)

Adam Danz
Adam Danz el 19 de Jun. de 2019
Editada: Adam Danz el 24 de Jun. de 2019
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);

Categorías

Más información sobre Animation en Help Center y File Exchange.

Productos


Versión

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by