# PCA in Matlab: why is the number of PCs always equal to the number of rows/observations minus 1? [duplicate]

I am currently trying to use classification analysis for some EEG data. As such data is of very high dimensionality, I am looking at using PCA for dimensionality reduction to prevent overfitting of the classification models.

My data structure is approximately 50 (rows, observations) times 38000 (columns, variables). I used the Matlab ‘pca’ function to generate principal components from my variables. I have three questions about this.

1. First, as stated on the Mathworks website (https://uk.mathworks.com/help/stats/pca.html), rows of the input matrix X should correspond to observations and columns to variables, which is the case for my approach. However, the number of principal components is always equal to rows/observations-1 (I tried using different numbers of rows). Why is this the case? Should it be this way? To me, it would be more intuitive if the number of (maximal) components would be equal to columns/variables-1.

2. Also, I observed that the sum of the output variable ‘explained’ is always 100, whether I have 5 or 50 principal components. Am I right to assume that this variable therefore does not refer to the proportion of the original data’s variance explained by the principal components but rather reflects the spread of ‘principal component’ variance across individual components? How can I find out the former? That is, how much of my data’s variance is included in the resulting principal components? Or do principal components always reflect the whole variance, no matter how few they might be?

3. Finally, I understand the ‘scores’ variable so that it reflects my data’s variance, meaning that it can be used analogously to my original data’s variables (e.g. columns). Is this right? Or do I have to project my data back to the original axes after performing PCA and using only a subset of the components? If so, how do I then even reduce input dimensions? I tried ‘reversing’ PCA and I received the same number of variables as before, just with different values in the matrix.