Search code examples
matlabvectormagnitude

MATLAB obtain vector magnitude matrix


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))?


Solution

  • You can also use hypot:

    result = hypot(Vx, Vy);
    

    According to the documentation,

    C = hypot(A,B) returns sqrt(abs(A).^2+abs(B).^2) carefully computed to avoid underflow and overflow.