One approach —
L = 1600; % Vector Lengths
t = linspace(0, 16*pi-(1/L), L); % Eight Cycles
r = 1; % Radius
x = r*cos(t); % X-Coordinate
y = r*sin(t); % Y-Coordinate
tz = linspace(0, t(end), fix(L/2)); % Length Governs Frequency Of Oscillation
zv = (1+sin(tz))*4; % Oscillation
figure
for k = 1:numel(z)
z = linspace(0, zv(k), L)+2; % Define Spring Length For This Cycle
plot3(x, y, z, 'LineWidth',2.5) % Draw Spring
axis([-1.5 1.5 -1.5 1.5 0 10]) % Fix Axis Limits
grid on % Draw Grid
drawnow % Animate
end
It does not show the animation here, however it does work.
Experiment with it to get the result you want. (I did my best to document it in the comments.) In the loop, the ‘z’ value controls the length for each iteration, using the ‘zv’ value, however ‘zv’ can be anything. It does not have to be the vector I used here to test the code, so in reality it will be related to something in your animation. I have drawn it vertically here, however by changing the order of the plot3 call arguments, you can put it in different orientations. You can also use the rotate function to put it in other orientations, if necessary.
.