# How to calculate variance - covariance matrix of a matrix?

For example, we have an NxP matrix with N rows and P variables. Then we need to calculate a PxP sample covariance matrix. How do I do that?

The sample covariance of N observations of K variables is the K-by-K matrix $\bar{\bar q}=[[q_{jk}]]$ with the entries
$q_{jk}=\frac{1}{N-1}\sum_{i=1}^{N}\left( x_{ij}-\bar{x}_j \right) \left( x_{ik}-\bar{x}_k \right)$,
which is an estimate of the covariance between variable $j$ and variable $k$.
All I can think to add is that the diagonal entries $q_{jj}$ are equivalent to the variables' variances $(s^2)$.
cov(yourMatrix)