半径1、中心(0,0​)の円をy>=0で赤​、それ以外を青。if​とforを用いてプロ​ットしたいです。自分​で何十回とやってみた​のですがどうもうまく​いきません。どなたか​ご助力いただけると幸​いです。

for c=0:360
x=cos(deg2rad(c))
y=sin(deg2rad(c))
if y>=0
plot(x,y,'-ro');
else
plot(x,y,'-bx');
end
end

 채택된 답변

Atsushi Ueno
Atsushi Ueno 2021년 6월 28일

1 개 추천

足りないのは、hold onです。
hold onを削除して、forループ内にpauseを置くと、何が起こっていたか理解する事が出来ます。
figure
hold on % 現在のプロット(figure)を保持する
for c=0:360
x=cos(deg2rad(c));
y=sin(deg2rad(c));
if y>=0
plot(x,y,'-ro');
else
plot(x,y,'-bx');
end
pause(0.01);% ウェイトを追加(動きを理解するのに役立ちます)
end
hold off % hold onを解除する

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 2 次元および 3 次元プロット에 대해 자세히 알아보기

제품

릴리스

R2021a

질문:

2021년 6월 27일

답변:

2021년 6월 28일

Community Treasure Hunt

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

Start Hunting!