how to prevent scatter handle deletion!

5 vues (au cours des 30 derniers jours)
john_arle
john_arle le 26 Oct 2019
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));
  1 commentaire
john_arle
john_arle le 26 Oct 2019
Modifié(e) : john_arle le 26 Oct 2019
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));

Connectez-vous pour commenter.

Réponse acceptée

john_arle
john_arle le 26 Oct 2019
See my comment above.

Plus de réponses (0)

Catégories

En savoir plus sur Training and Simulation dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by