I need to plot a Dynamic scattered plot. I have vector x and y, and those are coordinates. I need to plot coordinate 1, and then coordinate 2 but coordinate 1 must need to still there.

4 visualizaciones (últimos 30 días)
Hi everyone, i need to do a dynamic plot.I have 2 vectors, x & y. So i have a coordinate (x,y). For example, i have (0,0) , (1,1), (3,3) , (4,4) and so on, and first i need a point or a dot at (0,0) and then (1,1). then (2,2) but (0,0) and (1,1) must still there in the plot. So the plot will be like a lot of points but ploted dynamically. This is my code:
clear all
clc
close all
table = readtable('laser_data.csv');
array = table2array(table);
for i = 1:length(array)
%LEFT
hold on
for k = 2:2:30
x = -0.018+array(i,k);
y = 0.0899+array(i,k+1);
xlabel('Distancia en el eje X')
ylabel('Distancia en el eje Y')
title('Obstáculos')
h = scatter(x, y, 10, 'r');
drawnow limitrate
%pause(0.00001)
end
drawnow
%FRONT
for k = 32:2:60
x = 0.05620-array(i,k+1);
y = array(i,k);
xlabel('Distancia en el eje X')
ylabel('Distancia en el eje Y')
title('Obstáculos')
h = scatter(x, y, 10, 'r');
drawnow limitrate
%pause(0.00001)
end
drawnow
%RIGHT
for k = 62:2:90
x = 0.018-array(i,k);
y = -0.0899-array(i,k+1);
xlabel('Distancia en el eje X')
ylabel('Distancia en el eje Y')
title('Obstáculos')
h = scatter(x, y, 10, 'r');
drawnow limitrate
% pause(0.00001)
end
drawnow
end
But it takes like 30 minutes to plot, and using this one: just takes 30 secs but i dont want lines, i want points.
table = readtable('laser_data.csv');
array = table2array(table);
h = animatedline('Marker','none');
for i = 1:length(array)
%LEFT
for k = 2:2:30
x = -0.018+array(i,k);
y = 0.0899+array(i,k+1);
xlabel('Distancia en el eje X')
ylabel('Distancia en el eje Y')
title('Obstáculos')
addpoints(h,x,y)
drawnow limitrate
%pause(0.00001)
end
%FRONT
for k = 32:2:60
x = 0.05620-array(i,k+1);
y = array(i,k);
xlabel('Distancia en el eje X')
ylabel('Distancia en el eje Y')
title('Obstáculos')
addpoints(h,x,y)
drawnow limitrate
%pause(0.00001)
end
%RIGHT
for k = 62:2:90
x = 0.018-array(i,k);
y = -0.0899-array(i,k+1);
xlabel('Distancia en el eje X')
ylabel('Distancia en el eje Y')
title('Obstáculos')
addpoints(h,x,y)
drawnow limitrate
% pause(0.00001)
end
end

Respuesta aceptada

dpb
dpb el 4 de Ag. de 2020
Editada: dpb el 4 de Ag. de 2020
h = animatedline('Marker','none');
There's your problem...
array=readmatrix('laser_data.csv'); % no point in a table to just convert to array...
hAL=animatedline('Marker','.','MarkerSize',3,'LineStyle','none'); % set a point marker, no line...
xlabel('Distancia en el eje X') % don't update static info every pass through loop
ylabel('Distancia en el eje Y')
title('Obstáculos')
for i=1:size(array,1) % length() is risky
%LEFT
for k = 2:2:30
x = -0.018+array(i,k);
y = 0.0899+array(i,k+1);
addpoints(hAL,x,y)
drawnow limitrate
%pause(0.00001)
end
...
Make same changes in rest. It would be better to factor code so don't have repeated identical loops with just constants changing between, but that's another exercise...
  8 comentarios
dpb
dpb el 4 de Ag. de 2020
Huh. I don't know how I missed the 'LineStyle','none' parameter...what happens when just retype instead of cut 'n paste. Sorry about that...

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

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

Community Treasure Hunt

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

Start Hunting!

Translated by