# 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.

조회 수: 2(최근 30일)
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
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.
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')
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')
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')
drawnow limitrate
% pause(0.00001)
end
end

댓글을 달려면 로그인하십시오.

### 채택된 답변

dpb 4 Aug 2020
편집: dpb 4 Aug 2020
h = animatedline('Marker','none');
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);
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

표시 이전 댓글 수: 5
Santiago Villamil 4 Aug 2020
Thank you very much! It helps a lot!!!
dpb 4 Aug 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...
Santiago Villamil 5 Aug 2020
Thanks man, No problem!, it helps a lot also!!

댓글을 달려면 로그인하십시오.

### Community Treasure Hunt

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

Start Hunting!

Translated by