그래프를 따라 움직이는 또 다른 그래프

sin 함수를 따라 움직이는 원을 제가 임의로 설정하고 싶은데 어떻게하면 되는지 궁금합니다
임의의 원의 중심이 sin함수를 따라 움직이는것을 표현하고 싶습니다.

Respuestas (1)

Angelo Yeo
Angelo Yeo el 26 de Dic. de 2023

0 votos

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

Categorías

Preguntada:

el 24 de Mayo de 2020

Respondida:

el 26 de Dic. de 2023

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!