How to do projections of data in MATLAB?

909 Views Asked by At

How to project a matrix e.g $$A = \begin{bmatrix}2& 5& 4\\ 3& 8& 9\\ 12& 11& 5\\ 4& -7 &8\end{bmatrix}$$ and get the vector_of_projected_points (VPP) onto the following:

  • X and Y axis
  • Principal component and a perpendicular line to it
  • Some random/example lines so I can understand it better

I know that VPP = (P^T) * A , where P^T is the transpose of a projection vector(i also don't know how to compute one) that has ||P|| = 1 and has dx1 elements and A is my matrix which has dxd elements in this example 4$\times$3. I'm new to MATLAB so I would really appreciate your help! Thanks!

1

There are 1 best solutions below

0
On BEST ANSWER

The projection of $v$ in the direction of $P$ involves both the scalar value (dot product, calculated as $P^T v$) and the direction. So, the final result should be

 (P'*V)*P     % or 
 (V'*P)*P     % which is the same

Note that $P$ here has length one. To get the length one, take your original vector and divide by its length. For example,

 V = [1 2 3]';
 P0 = [1 1 0]'; 

 P = P0/norm(P0);
 projV = (V'*P)*P

To project the matrix, you project every column of the matrix.