# MATLAB: How to continuously update data for two plots (plotted on the same axis using plot on)

animationaxeschildrendrawnowhold onloopobjectplotplot3springsubplotzdata

I have written a code to
• Draw a spring
• Draw a point on the spring
• Animate the spring (up and down)
• Animate the point to move along with the spring
Now, the animation works till the point where the spring alone has to move. If I try to plot the point, the animation stops and the spring and the point appear stationary.
I have plotted the spring and the point together on the same subplot (of an axes handle in a GUI). How can I update the Zdata of both the plots in a loop?
time = 0:pi/50:25*pi;   % Time arrayradius = 2;             % Radius of the coil springheight = 10;             % Height of the coil springx = sin(time) * radius; % Compute x and yy = cos(time) * radius;z = height/(2*pi) * time;   %Compute z which will be used later to animateaxis offha1 = subplot(1,2,1,handles.axes1);plot3(x,y,z,'Linewidth',2);set(ha1,'Position',[.016 .044 .142 .274]);hold onplot3(1.275, 1.545, 121.1, 'diamond',...     'LineWidth',1,...     'MarkerSize',10,...     'MarkerEdgeColor','b',...     'MarkerFaceColor', [0.7 0.7 0.7]); pause('on'); axis off ;  while 1      t=0; axis off;       for t= 0:1:1000          zaddf = sind(2.5*2*pi*t);          znewf = z + zaddf;         Zdataarray = {znewf , zaddf + 121.1} ;                     hChildren1 = get(handles.axes1,'Children');          axis off          set(hChildren1,'ZData',Zdataarray);                  drawnow;          pause(0.005);      end  end
When I run this code, the ZDataarray variable (concept suggested by this answer) becomes a cell with two elements – one a [1 X 1251] array and the other a single numerical value. I am not able to set the ZData of both the plots in a loop.
When I try with this code,
set(hChildren1,'ZData',znewf);
the spring animation works perfectly on its own, without the point on it.
How can I update both plots simultaneously, in a loop?
hLine1 = plot3(x,y,z,...)hLine2 = plot3(1.275, 1.545,...)while 1   ...   set( hLine1, 'ZData', zaddf + 121.1 );   set( hLine2, 'ZData', znewf );   ...end