I had to add hold on instruction after the first scatter instruction. Otherwise, Matlab next scatter deletes the previous one no matter what.
Thank you, John!
if self.plot_initialized == 0
self.figure_handle = figure; clf;
grid on;
colours = swarm.get_colors();
size_agents = repmat(30, swarm.nb_drones, 1);
pn = x_current(:,1);
pe = x_current(:,2);
pd = x_current(:,3);
self.scatter_handle = scatter3(pe, pn, -pd, size_agents, colours', 'filled');
for agent = 1:swarm.nb_drones
self.wake = zeros(10, 3, swarm.nb_drones);
for i = 1:10
self.wake(i, 1:3, agent) = x_current(1:3, agent);
end
end
xlabel('Y position [m]');
ylabel('X position [m]');
zlabel('Z position [m]');
axis square;
view(0,90);
grid on;
hold on; % HERE IT IS WHERE I INSERTED A HOLD ON LINE!
self.plot_initialized = 1;
%----------------------------------------------------------
else
size_agents = repmat(30, swarm.nb_drones, 1);
colours = swarm.get_colors();
pn = x_current(:,1);
pe = x_current(:,2);
pd = x_current(:,3);
set(self.scatter_handle, 'Xdata', pe, 'Ydata', pn, ...
'Zdata', -pd, 'Marker', '.', 'SizeData', ...
size_agents, 'CData', colours');
colour = 200*ones(10, 3);
for agent = 1:swarm.nb_drones
self.scatter_handle
agent
self.wake = circshift(self.wake, 1);
self.wake(1, :, agent) = x_current(:, agent);
self.lines_handle(agent) = scatter(...
self.wake(1:end, 2, agent), ...
self.wake(1:end, 1, agent), 4, colour);
% Here it is where scatter_handle gets deleted!
self.scatter_handle
end
drawnow;
end
title(sprintf('Simulation time: %.2f seconds', time));