无法在 matlab 中使用 ezplot 绘制圆

Cannot plot circle with ezplot in matlab

我想在图形 MATLAB 中绘制 6 个圆。但是不能出现。

我认为这段代码是正确的,我尝试给出轴限制。但它无法解决我的问题。

clear all;
clc;
p=[8 9 3 4 7 4];
rtopi=[3 4 16 25 34 25];
n=length(p);
for ii=1:n
    f=@(x,y)(x-p(ii)).^2+(y).^2-rtopi(ii)^2;
    gambar=ezplot(f);
    set(gambar,'color','k','linewidth',2);
    grid on;
    axis equal;
    set(gca,'Color','y');
    xlabel('Real');
    ylabel('Imaginary');
    title('Discs');
    axis([-30 30 -30 30]);
end

这是结果:

如何解决?

去掉函数定义中的.*,只用x^2而不是x.^2.

在循环结束前使用'hold on'

将背景颜色、打开的网格、标题等移到循环外。

最重要的是,为 ezplot 声明 xmin、xmax。默认值为(-2pi 至 2pi)。 尝试:gambar = ezplot(f,[xmin,xmax}) 并使用 xmin 和 xmax

的绘图限制