I have 2 matrices containing 2D data on spatial components of Vx and Vy motion vector components.
How to I easily combine the 2 matrices to obtain the magnitude matrix (sqrt(Vx^2+Vy^2))?
I have 2 matrices containing 2D data on spatial components of Vx and Vy motion vector components.
How to I easily combine the 2 matrices to obtain the magnitude matrix (sqrt(Vx^2+Vy^2))?
You can also use hypot
:
result = hypot(Vx, Vy);
According to the documentation,
C = hypot(A,B)
returnssqrt(abs(A).^2+abs(B).^2)
carefully computed to avoid underflow and overflow.
To calculate the magnitude of two matrices it is the same procedure as with scalar values. The only difference is that before the power operator you have to put a point (.
) to differenciate that you don't want to do it in a matrix way, only element by element.
M=sqrt(Vx.^2+Vy.^2);