how to make a covarinace matrix using data from excel?
2 次查看(过去 30 天)
显示 更早的评论
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!!
0 个评论
回答(1 个)
Bjorn Gustavsson
2021-2-16
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
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spreadsheets 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!