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

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

답변 (1개)

Angelo Yeo
Angelo Yeo 2023년 12월 26일

0 개 추천

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

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

질문:

2020년 5월 24일

답변:

2023년 12월 26일

Community Treasure Hunt

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

Start Hunting!