I've made 3D animation (.avi) with "scatter3". I have 3 sets of data points where X,Y (both are matrix 1 by 24) are fixed data points and Z is matrix 485 by 24 (only Z coordinate changes with time).
I also include grid using "mesh", where all data points have z equal to 0. This is just to illustrate plane z=0, because my data points alternate between -14 and 15.
Now I would like to add dynamic labels for each point (24). I did this with "text" but it doesn't work at all, because during the animation labels are completely blotted. Animation shows label positions one by another but problem is that animation doesn't erase all the previous label positions before next is shown.
Here is the section of my code where I create the animation:
...
X=[]; % x - coordinate for each of 24 points
Y=[]; % y - coordinate -||-
Z=[]; % z - coordinate -||-
labels=[]; % 24 different labels
a=1:1:24;
b=1:1:24;
[aa bb]=meshgrid(a,b);
c=aa*0+bb*0;
writerObj=VideoWriter('my_animation.avi');
open(writerObj);
frames=485;
mov(1:n_frame)=struct('cdata',[],'colormap',[]);
set(gca, 'nextplot','replacechildren');
f=figure(1);
set(f,'Position',[150 80 1600 900]);
plot_1=scatter3(X,Y,Z(1,:)); % all 24 points at time t=0;
hold on;
net=mesh(a,b,c,'EdgeColor',[0 0 0],'FaceColor','none'); % grid at z=0
for k=1:frames
set(plot_1, 'ZData',Z(k,:)); % "k" goes from 1 to 485 for all 24 points
set(net, 'ZData'); % mesh is static all the time
text(X,Y,Z(k,:),labels); % each point has its own label
view(-30,50);
mov(k)=getframe(gcf);
writeVideo(writerObj,mov(k));
end
Any ideas how could I fix this? I tried with "drawnow update" and "refreshdata" inside of for loop but it doesn't help.