On the number of principal components: A test of dimensionality based on measurements of similarity between matrices