Hello!
In a for loop, I first initialize a scatter plot, and then I update it.
However, when adding a second handle (lines_handle) to my code,
the former (scatter_handle) tells me that the object scatter has been deleted.
It is probably because I am assigning another scatter plot to lines_handle.
I believe this should not happen and most of all I do not know how to prevent it.
Thank you.
You can see my code below, look at the only comment to see where the scatter object is deleted!
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; 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));
Best Answer