How can we find the angle or orientation of the 1st Principal Component

How can I calculate the angle of the 1st Principal component found after PCA. I am using Princomp(). My data is a set of co-ordinates in 2D. For example, X={0,1,2,3,4,5,6,7,8,0}, Y=(0,2,3,2,2,3,2,2,2,0}.
Please advice how to calculate the angle/orientation of the 1st principal component. Thank you.

1 Comment

There should be lot of books about the subject. This doesn't seem to be a matlab-related question.

Sign in to comment.

Answers (1)

Hi Nabin,
To calculate the angle of the first principal component after performing PCA on a set of 2D coordinates, you can follow these steps. The angle gives you the orientation of the principal component in relation to the coordinate axes.
% Your data points
X = [0, 1, 2, 3, 4, 5, 6, 7, 8, 0];
Y = [0, 2, 3, 2, 2, 3, 2, 2, 2, 0];
% Combine into a matrix
data = [X' Y'];
% Perform PCA
[coeff, score, latent] = princomp(data);
% Extract the first principal component
firstPC = coeff(:, 1);
% Calculate the angle in radians
angleRad = atan2(firstPC(2), firstPC(1));
% Convert the angle to degrees
angleDeg = rad2deg(angleRad);
% Display the angle
disp(['Angle of the first principal component (in degrees): ', num2str(angleDeg)]);

Categories

Asked:

on 1 Oct 2012

Answered:

on 3 Feb 2025

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!