半径1、中心(0,0)の円をy>=0で赤、それ以外を青。ifとforを用いてプロットしたいです。自分で何十回とやってみたのですがどうもうまくいきません。どなたかご助力いただけると幸いです。
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
笙瑛 深谷
el 27 de Jun. de 2021
Respondida: Atsushi Ueno
el 28 de Jun. de 2021
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
0 comentarios
Respuesta aceptada
Atsushi Ueno
el 28 de Jun. de 2021
足りないのは、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 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre 2 次元および 3 次元プロット en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!