MATLAB中的ezplot,如何使用函数句柄进行绘图? [英] ezplot in MATLAB, how to plot using a function handle?
问题描述
我已经尝试过了:
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限制是我正在处理的图像的大小.我正在尝试绘制一组对极线.有什么建议吗?
aa
,ba
,ca
are all known values (column vectors). The x and y limits are the size of the image that I'm working with. I'm trying to plot a set of epipolar lines. Any suggestions?
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
推荐答案
据我所知,ezplot
不能绘制像plot
这样的一系列线.解决此问题的一种方法是将参数k
添加到匿名函数中,该函数用于选择当前行.然后,您可以遍历for循环中的所有行并将它们逐一绘制.
As far as I know, ezplot
can not plot a series of lines like plot
. A way to work around this would be to add a parameter k
to the anonymous function, which is used to select the current line. You can then go through all lines in a for loop and plot them one-by-one.
进一步:如 ezplot
帮助页面所述,您必须使用数组函数.*
,./
和.^
,所以ezplot
可以使用向量来评估函数.
Further: as it is stated on the ezplot
help page, you have to use the array functions .*
, ./
and .^
, so ezplot
can use vectors to evaluate the function.
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
这篇关于MATLAB中的ezplot,如何使用函数句柄进行绘图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!