本文基于MATLAB,采用两种方式绘制圆,一种是直角坐标系下plot(x,y)绘制圆,另外一种是极坐标系下polar(theta,rho)绘制圆。

第一,启动MATLAB,新建脚本(Ctrl+N),输入以下代码: close all; clear all; clc r=2; theta=0:pi/100:2*pi; x=r*cos(theta); y=r*sin(theta); rho=r*sin(theta); figure(1) plot(x,y,'-') hold on; axis equal fill(x,y,'c') figure(2) h=polar(theta,rho); set(h,'LineWidth',2)
02第二,保存和运行上述脚本,在figure(1)中得到plot(x,y)和fill(x,y)绘制的圆。
03第三,保存和运行上述脚本,在figure(2)中得到polar(theta,rho)绘制的圆。
04第四,可以将plot(x,y),polar(x,y)绘制的圆画在一张图上,只需要接着输入以下代码: figure(3) subplot(1,2,1);plot(x,y,'-');hold on; axis square fill(x,y,'c') subplot(1,2,2);h=polar(theta,rho);set(h,'LineWidth',2)
05第五,保存和运行上述增加后的脚本,在figure(3)中将plot(x,y),polar(x,y)绘制的圆画在了一张图上。
本文地址:网络知识频道 https://www.hkm168.com/jiqiao/1035816.html,易企推百科一个免费的知识分享平台,本站部分文章来网络分享,本着互联网分享的精神,如有涉及到您的权益,请联系我们删除,谢谢!



相关阅读








