MATLAB: How to loop through 40 lines of data every time step.

3d plotsfor loopiteration

I am trying to create an animation of 40 particles moving. I want to create a for loop that goings through 40 lines of my data every iteration so I can plot 40 particles per frame in the movie. I want to plot 40 particles per iteration.
link to the data data.20.csv
table = readtable('data20.csv');
data = table2cell(table);
y = [data{:,5}];
x = [data{:,4}];
z = [data{:,6}];
time = [data{:,2}];
% axes([x(1) x(1,end) y(1) y(1,end) z(1) z(1,end)])
for i = 1:length(time)
for k = 1:20;
X = data{k,4};
Y = data{k,5};
Z = data{k,6};
[X,Y,Z] = particle_ID;
end
plot3(X,Y,Z)
iteration = particle_ID
end

Best Answer

Something like this
table = readtable('data20.xlsx');
data = table2cell(table);
y = [data{:,5}];
x = [data{:,4}];
z = [data{:,6}];
time = [data{:,2}];
%%
fig = figure();
ax = axes('Projection', 'perspective');
axis([min(x) max(x) min(y) max(y) min(z) max(z)])
hold on;
grid on;
view(3)
p = plot3(0,0,0, 'bo', 'LineWidth', 2);
[X, Y, Z] = deal(zeros(40,1));
v = VideoWriter('myAnimation.mp4', 'MPEG-4');
open(v);
for i = 1:length(time)/40
for k = 1:40
X(k) = x((i-1)*40+k);
Y(k) = y((i-1)*40+k);
Z(k) = z((i-1)*40+k);
end
p.XData = X;
p.YData = Y;
p.ZData = Z;
drawnow;
frame = getframe(fig);
writeVideo(v, frame.cdata);
end
close(v)
It will save the animation in an mp4 file
Related Question