Hi Liana, what you're trying to do with your data points isn't very evident, since there are no images attached. According to my understanding of the problem, I've made certain assumptions:
- The kind of plot you end up with, is something like this:
- Here, you want to avoid the vertical-looking lines, because they're part of a different series of data. What do I mean by series? A sequence of x,y,z values until z reaches 18.
- These vertical lines are a result of animatedline taking the last data point from the previous series and starting your line from there. (Assuming this is what you meant by 'continuously')
- The kind of output you're looking for:
(Here, I've just plotted different series with different colors to show that they're separate. You'll notice that the vertical lines are absent)
Solution
Here's your code with some minor changes to keep track of the periodic boundary condition:
contents = fileread('results.txt');
contents = strsplit(contents, 'Particle');
particles = cellfun(@(c) sscanf(c, '%f', [3 Inf])', contents(2:end), 'UniformOutput', false);
view(3);
flag=0;
curve=animatedline('linewidth',2,'color',rand(1,3));
for j=1:length(particles{1,1})
x = particles{1,1}(j,1);
y = particles{1,1}(j,2);
z = particles{1,1}(j,3);
if(z==18)
flag = j;
end
if j~=flag+1
addpoints(curve,x,y,z);
drawnow
else
curve=animatedline(x,y,z,'linewidth',2,'color',rand(1,3));
addpoints(curve,x,y,z);
drawnow
flag=0;
end
pause(0.2);
end
So in essence, all that needed to be done is re-initializing an animated line with the points from the new sequence, so that it doesn't construct lines from the old points.
Hope this helps.