【问题标题】:ezplot in MATLAB, how to plot using a function handle?MATLAB中的ezplot,如何使用函数句柄进行绘图?
【发布时间】:2015-03-03 05:55:41
【问题描述】:

我试过了:

linefunca = @(xa,ya) aa*xa + ba*ya + ca;

figure(1)
imshow(Pica);
hold on;
ezplot(linefunca,[1,1072,1,712]);

但我返回此错误:

 In an assignment  A(I) = B, the number of elements in B and I must be the same.

Error in ezplotfeval/applyfun (line 80)
       z(i) = feval(f,x(i),y(i));

Error in ezplotfeval (line 65)
    z = applyfun(x,y);

Error in ezplot>ezimplicit (line 257)
u = ezplotfeval(f, X, Y);

Error in ezplot (line 153)
            hp = ezimplicit(cax, f{1}, vars, labels, args{:});

Error in ps3 (line 313)
ezplot(linefunca,[1,1072,1,712]);

aa,ba,ca 都是已知值(列向量)。 x 和 y 限制是我正在使用的图像的大小。我正在尝试绘制一组极线。有什么建议吗?

编辑:

lt = length(aa);
linefunca = @(x,y,t) aa.*x(t) + ba.*y(t) + ca(t);
figure(1)
imshow(Pica);
hold on;

for t=1:lt
    ezplot(@(x,y,t) linefunca(x,y,t),[1,lt]);
end

【问题讨论】:

    标签: matlab plot function-handle


    【解决方案1】:

    据我所知,ezplot 无法绘制像plot 这样的一系列线条。解决此问题的一种方法是将参数k 添加到匿名函数,用于选择当前行。然后,您可以遍历 for 循环中的所有行并逐个绘制它们。

    进一步:正如ezplot help page 中所述,您必须使用数组函数.*./.^,因此ezplot 可以使用向量来评估函数。

    N = 5;
    aa = rand(N,1); ba = rand(N,1); ca = rand(N,1);
    linefunca = @(xa,ya,k) aa(k).*xa + ba(k).*ya + ca(k);
    
    hold on
    for k=1:N
        ezplot(@(x,y)linefunca(x,y,k),[-5,5,-5,5]);
    end
    hold off
    

    【讨论】:

    • 感谢您的帮助,但这给了我同样的错误。
    • 您确定添加了.* 吗?如果我从我的答案中复制示例代码,它可以正常工作。
    • 我没有完全按照你写的那样复制它;我在我的代码中尝试过。查看我的编辑。
    • 尝试将 for 循环中的部分更改为ezplot(@(x,y) linefunca(x,y,t),[1,lt]);,因为ezplot 函数应该将t 视为常量值,而不是linefunca 的变量。
    • 啊刚刚发现其他东西:你写了x(t)y(t)而不是aa(t)ba(t)。请更改此设置,然后它应该可以工作。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-03-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-14
    • 1970-01-01
    相关资源
    最近更新 更多