C = cov(___,w)
- It returns the covariance of the input array by normalizing it to w.
- If w = 1, then covariance is normalized by the number of rows in the input matrix.
- If w = 0, then covariance is normalized by the number of rows in the input matrix – 1.
Example:
Matlab
% Input vector A = [2 4 6; 3 5 7 8 10 12]; disp( "Matrix :" ); disp(A); % Variance of matrix A C = cov(A,1); disp( "Variance matrix:" ); disp(C); |
Output :
How to Calculate Covariance in MATLAB
Covariance is the measure of the strength of correlation between two or more random variables. Covariance of two random variables X and Y can be defined as:
Where E(X) and E(Y) are expectation or mean of random variables X and Y respectively.
The covariance matrix of two random variables A and B is defined as
MATLAB language allows users to calculate the covariance of random variables using cov() method. Different syntax of cov() method are:
- C = cov(A)
- C = cov(A,B)
- C = cov(___,w)
- C = cov(___,nanflag)
Contact Us