简体   繁体   English

matlab-从矩阵获取向量(quiverplot)

[英]matlab - get vectors from a matrix (quiverplot)

I am reading in an image and storing it into a 2d matrix. 我正在读取图像并将其存储到2D矩阵中。 after doing some computation on it as shown here: 在对其进行一些计算之后,如下所示:

im = rgb2gray(imread('ellipse.png'));
im = im(:,:,1);
w = size(im,1);                   
h = size(im,2);                               
[dx,dy] = gradient(double(im));                
[x y] = meshgrid(1:h,1:w);                    
a = zeros(temp);
lambda = 1;
Ox =-1.^lambda.* -x;
Oy =-1.^lambda.* y;
hold on                                   
quiver(x,y,Ox,Oy)  

I get the following image from the quiverplot: 我从quiverplot获得以下图像:

https://docs.google.com/file/d/0B0iDswLYaZ0zR2lUQ2NkZnd1QXM/edit?pli=1 https://docs.google.com/file/d/0B0iDswLYaZ0zR2lUQ2NkZnd1QXM/edit?pli=1

My question is, how do I access those vectors (arrows) from the quiverplot? 我的问题是,如何从quiverplot中访问这些向量(箭头)? I need to use those vectors in a cross product later on. 稍后,我需要在叉积中使用这些向量。 Thanks. 谢谢。

An easy way would be stack your matrices into a big NxMx3 block and call cross against it like this: 一种简单的方法是将矩阵堆叠到一个大的NxMx3块中,并像这样对它进行交叉调用:

myVectors = cat(3, Ox, Oy, zeros(size(Ox)));
someOtherVectors = myVectors+1;
result = cross(myVectors,someOtherVectors );

Another would be to write your own cross function like this: 另一个方法是编写自己的交叉函数,如下所示:

function result = cross2d(Ax, Ay, Bx, By)
      result = Ax.*By - Ay.*Bx;
end

And call it like this in your code: 并在您的代码中这样调用它:

Mx = Ox + 1;
My = Oy + 1;

result2 = cross2d(Ox, Oy, Mx, My)

(Note that I just made up a new set of vectors to take the cross product against by adding one... you would use your own) (请注意,我只是组成了一组新的向量,通过添加一个向量来求叉积...您将使用自己的向量)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM