使用MATLAB畫圓的方法有兩種,分別如下:
1、啟動MATLAB,新建腳本,輸入以下代碼:
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)
2、保存和運行上述腳本,在figure(1)中得到plot(x,y)和fill(x,y)繪制的圓。
3、使用plot(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)
4、點擊保存並運行。