drawnow 함수를 이용하면 애니메이션을 그릴 수 있습니다.
아래는 sine 함수를 따라 움직이는 원에 관한 예시입니다.

n = 100;
t = linspace(-1, 1, n);
x = sin(2*pi*1*t);
close all;
fig = figure(1);
plot(t, x, 'color', lines(1))
axis([-1, 1, -1, 1])
axis square
hold on;
theta = linspace(0, 2*pi, n);
r = 0.1;
for i = 1:n
h = plot(t(i) + r * cos(theta), x(i) + r * sin(theta), 'color', lines(1));
drawnow
% exportgraphics(gca, "foo.gif", "Append", true) % gif 파일로 출력하는 경우
if i < n
delete(h)
end
end