-1

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

2one
  • 1,035
  • 3
  • 17
  • 36

2 Answers2

3

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.

Luis Mendo
  • 110,752
  • 13
  • 76
  • 147
1

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