how to make a covarinace matrix using data from excel?

2 views (last 30 days)
Hello!
I am new to MATLAB and need help with making a covariance matrix
I have data in the following format
Date A B C D E
11.02.2021 8,506 8,654 14,396 17,648 7,457
10.02.2021 8,394 8,678 14,263 17,799 7,481
I need to make a 5X5 matrix and store the value in a variable.
Please Help!!

Answers (1)

Bjorn Gustavsson
Bjorn Gustavsson on 16 Feb 2021
Just use cov. From the help of the cov-function:
cov Covariance matrix.
cov(X), if X is a vector, returns the variance. For matrices, where
each row is an observation, and each column a variable, cov(X) is the
covariance matrix. DIAG(cov(X)) is a vector of variances for each
column, and SQRT(DIAG(cov(X))) is a vector of standard deviations.
cov(X,Y), where X and Y are matrices with the same number of elements,
is equivalent to cov([X(:) Y(:)]).
So just extract your [ n_obs x 5 ] data from your excell-file and send that matrix to the cov-function.
HTH

Community Treasure Hunt

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

Start Hunting!