
使用MATLAB画圆的方法有两种,分别如下:
1、启动MATLAB,喊穗隐新建脚本,输入以下代码:
close allclear allclc
r=2theta=0:pi/100:2*pi
x=r*cos(theta)y=r*sin(theta)
rho=r*sin(theta)
figure(1)
plot(x,y,'-')
hold onaxis equal
fill(x,y,'c')
figure(2)
h=polar(theta,rho)
set(h,'LineWidth',2)
2、保存和运行上述脚本,在figure(1)中得到plot(x,y)和fill(x,y)绘制的圆。
3、使用plot(x,y)画圆只需要接着输入以下代码:
figure(3)
subplot(1,2,1)plot(x,y,'-'郑厅)hold onaxis square
fill(x,y,'c')
subplot(1,2,2)h=polar(theta,rho)set(h,'LineWidth',2)
4、点击保存并运族启行。
可用如下代码,圆心,半径游中可修改:c=[0 0]%圆心
r=1 %半径
a=0:0.1:2*pi
x=c(1)+r*cos(a)
y=c(2)+r*sin(a)
plot(x,y,'贺慧r.'神拍山)
function[x,
y]
=
getCircle(center,
r)
t=0:0.01*pi:2*pi
x=cos(t).*r+center(1)y=sin(t).*r+center(2)
%例如迹档绘制(1,1)为圆心,半径2
%在命令窗口中运判州搜掘历行[x,
y]
=
getCircle([1,1],
2)plot(x,y)
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)