MATLAB Answers


Covariance calculation like excel formula

Asked by amir khalighi on 6 Apr 2018
Latest activity Edited by Pawel Jastrzebski on 18 Apr 2018
Hi When I calculate covariance in excel it gives me a number but in matlab it gives me a matrix,why is that?and how can I get the covariance amount like excel? thanks


Sign in to comment.

1 Answer

Answer by Pawel Jastrzebski on 6 Apr 2018
Edited by Pawel Jastrzebski on 18 Apr 2018
 Accepted Answer

Given the code:
A = randi([18 22], 20,1)
B = randi([15 25], 20,1)
C = cov(A,B)
This is the outcome that you'll get:
>> C
C =
1.6947 -0.2842
-0.2842 6.8842
The same data in excel produces the following:
So you get the same values. Read up the documentation for covariance. This is why you get a matrix of the results:

  1 Comment

very complete , thank you

Sign in to comment.