Problem 2049. Six Steps to PCA - Step 2: Covariance
Previous problems in this series
Step 2: Covariance
For the second step we want the covariance matrix of the centred and standardized data that we calculated in Step 1. We could conveniently use Matlab's cov function, but this repeats much of what we've already done, for instance centering by removing the mean. It also has to deal with a wider range of possible inputs, whereas we have a very well specified starting point.
Task
Build on the code produced for Step 1 by writing a function to calculate the covariance matrix of the centred and standardized data matrix.
Add the following field to those already produced by your zscore function.
- Cov: a square matrix of covariances
Tips
- It's not as complicated as it sounds. Write one new line of code.
- Don't just call Matlab's own cov function.
- Keep to the structure of the code template with zscore as a local function.
Solution Stats
Problem Comments
-
2 Comments
Where are the other steps Neil ?
The problem wants the covariance matrix of the z-score obtained at the previous step if someone else found the problem description unclear.
Solution Comments
Show commentsProblem Recent Solvers13
Suggested Problems
-
Project Euler: Problem 9, Pythagorean numbers
1151 Solvers
-
449 Solvers
-
Getting the absolute index from a matrix
246 Solvers
-
Remove the two elements next to NaN value
651 Solvers
-
409 Solvers
More from this Author1
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!