无法在Matlab中使用ezplot绘制圆

时间:2019-04-06 04:09:01

标签: matlab plot matlab-figure

我想在图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

这是结果:

enter image description here

如何解决?

1 个答案:

答案 0 :(得分:2)

删除函数定义中的。*,仅使用x ^ 2而不是x。^ 2。

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

将背景颜色,网格,标题等移动到循环之外。

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