two animated lines simultaneously with different number of sample

good evening, I'm trying to animate two line simultaneously, but I cant. I attach one if the last script, I even tried with only one for and the hold on after thefirst animatedline but still nothing.. I hope some can help me. I attach the 4 vector. x is with y; x1 with y1.
h = animatedline;
h1=animatedline;
axis([0,12,0,1])
numpoints = 2000;
numpoints1 = 20000;
x1=len_x1;
y1=len_y1;
x = len_x;
y = len_y;
a = tic; % start timer
% c=tic;
for k = 1:numpoints
addpoints(h,x(k),y(k))
b = toc(a); % check timer
if b > (1/100)
drawnow % update screen every 1/100 seconds
a = tic; % reset timer after updating
end
end
hold on
for j = 1:numpoints1
addpoints(h1,x1(j),y1(j))
b = toc(a); % check timer
if b > (1/10)
drawnow % update screen every 1/100 seconds
a = tic; % reset timer after updating
end
end
drawnow % draw final frame

 Accepted Answer

hello
I am not sure to uderstand what kind of result you want to achieve , maybe this little demo can help you
clearvars
clc
figure
h1 = animatedline;
h1.Marker = '*';
h1.Color = [1 0.4 0];
h2 = animatedline;
h2.Marker = '+';
h2.Color = [0 1 0];
axis([0 2*pi -1.5 1.5])
% x, y data
n = 100;
x=linspace(0,2*pi,n);
y1 = sin(x);
y2 = cos(x);
% main loop
for ci=1:n
addpoints(h1,x(ci),y1(ci));
addpoints(h2,x(ci),y2(ci));
pause(0.01);
drawnow
end

7 Comments

yeah I know, it's a little difficult to explain.. the problem is that I have two different number of "ci".. let's say that for y1=sin(x1), x1=1:10
for y2=cos(x2), x2=1:100
I want them to be let's say "matched". I don't know if I was clear.
If you run my script you will see the first plot and after it is compleatly plotted it starts the other one.. but they have two different "length of x"
hello
I ran your code and I can see your plotting two animated lines with very similar shape , but with different number of points (different delta x , 0.01 for first line and 0,001 for second line )
this is the same as my demo modified here below : one curve has 100 points and the first 10 points but they both describe the same sine wave
clearvars
clc
figure
h1 = animatedline;
h1.Marker = 'd';
h1.Color = [1 0.4 0];
h2 = animatedline;
h2.Marker = '*';
h2.Color = [0 1 0];
axis([0 2*pi -1.5 1.5])
% x1, y1 data
n1 = 10;
x1=linspace(0,2*pi,n1);
y1 = sin(x1);
% x2, y2 data : 10 times more samples vs x1,y1 data
k = 10;
n2 = k*n1;
x2=linspace(0,2*pi,n2);
y2 = sin(x2);
% main loop
for ci=1:n2
a = ceil(ci/k);
addpoints(h1,x1(a),y1(a));
addpoints(h2,x2(ci),y2(ci));
pause(0.01);
drawnow
end
Thank you so much! this is what i tried to achieve. but right now I'm trying to "control the velocity" in which they are displayed. changing the pause value doesn't give anything, is there a better way?
I still thank you!!!
hello
on my computer, matlab is not very fast... I can slow down the code , using pause(0.5) will be noticeable.
but pause(0.01); does not change anything as even without pause , the iteration is slower than 0.01 s
so it depends if you want to slow down or speed up your rendering. It may simply depends how fast matlab runs on your pc.
yes! sorry I thought I answered you! thank you so much for your help!

Sign in to comment.

More Answers (0)

Categories

Community Treasure Hunt

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

Start Hunting!