cov(X,Y) is equivalent to cov([x(:) y(:)]). But [x(:) y(:)] is 20000 by 2 for you, and cov() treats rows as observations and columns as dimensions, so you get a 2 by 2 covariance matrix.
I would just implement it myself by the definition:
bsxfun(@minus,x,mean(x))'*bsxfun(@minus,y,mean(y))/(size(x,1)-1)
If you have an older version of matlab that doesn't support bsxfun(), just use repmat().
MathWorks
mathworks.com › matlab › data import and analysis › descriptive statistics and insights
cov - Covariance - MATLAB
C = cov(A,B) returns the covariance between two random variables A and B.
MathWorks
mathworks.com › signal processing toolbox
Correlation and Covariance - MATLAB & Simulink
They estimate covariance and normalized covariance respectively between the different channels at lag 0 and arrange them in a square matrix. You clicked a link that corresponds to this MATLAB command:
02:59
How To Calculate Covariance In MATLAB? - The Friendly Statistician ...
07:39
Covariance Example | MATLAB (Without using built-in function) - ...
More Intuition About Eigen Vectors and data covariance ...
01:35
Covariance & Correlation Coefficient calculation in MATLAB without ...
MathWorks
mathworks.com › control system toolbox › linear analysis › time and frequency domain analysis
covar - Output and state covariance of system driven by white noise - MATLAB
This MATLAB function returns the steady-state output response covariance
MathWorks
mathworks.com › statistics and machine learning toolbox › cluster analysis and anomaly detection › anomaly detection
robustcov - Robust multivariate covariance and mean estimate - MATLAB
This MATLAB function returns the robust covariance estimate sig of the multivariate data contained in x.
GeeksforGeeks
geeksforgeeks.org › matlab › how-to-calculate-covariance-in-matlab
How to Calculate Covariance in MATLAB - GeeksforGeeks
July 23, 2025 - If A is a matrix, then it considers each column as a random variable and returns the covariance matrix of matrix A. Note: disp (x) displays the value of variable X without printing the variable name. Another way to display a variable is to type its name, which displays a leading “X =” before the value. If a variable contains an empty array, disp returns without displaying anything. Example 1: Matlab ·
MathWorks
mathworks.com › financial toolbox › portfolio optimization and asset allocation › mean-variance portfolio optimization › create portfolio
Comparison of Methods for Covariance Estimation - MATLAB & Simulink
Portfolio | covarianceShrinkage | covarianceDenoising | nearcorr ... Run the command by entering it in the MATLAB Command Window.
Johns Hopkins University
math.jhu.edu › ~shiffman › 370 › help › techdoc › ref › cov.html
cov (MATLAB Function Reference)
Description C = cov(x) where x is a vector returns the variance of the vector elements. 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 ...
Top answer 1 of 4
1
|cov| should be the function you use, what about it makes you confusing?
2 of 4
1
I know this question is old but I came across this page looking for the same answer. If the cov() function in Matlab had an input element option for the expected value of the two functions then it would work but it does not. The cov() function appears to be designed for a large data set where the mean value can be determined. In your case you will need to know the expected value of each of the random variables in your vector ahead of time. Then the covariance of that vector would be calculated with nested for loops iterating through the array and computing the elementwise covariance manually. The built in function cov() does not provide any options here. This is the video link that helped me: https://m.youtube.com/watch?v=0W8hTzU1ZMM It assumes that you have a vector of random variable values (instances) where each element represents the functions to be compared with covariance and that for each element in the vector you already know the expected value. Then it is easy to take an Nx1 vector and compute the NxN covariance matrix but tedious.
MathWorks
mathworks.com › statistics and machine learning toolbox › anova › analysis of variance and covariance
Analysis of Covariance - MATLAB & Simulink
Using analysis of covariance, you can model y as a linear function of x, with the coefficients of the line possibly varying from group to group.
MathWorks
mathworks.com › matlabcentral › answers › 436387-how-do-i-create-and-calculate-a-covariance-matrix-how-do-you-get-the-covariance
how do i create and calculate a covariance matrix? how do you get the covariance - MATLAB Answers - MATLAB Central
December 18, 2018 - Create and calculate the values for a 5x5 matrix where the (i, j) component contains the covariance of the set of measurements from row i with the set of measurements from row j. Sign in to comment. Sign in to answer this question. ... Sign in to answer this question. Find more on Generate Test Data in Help Center and File Exchange ... Find the treasures in MATLAB Central and discover how the community can help you!
MathWorks
mathworks.com › matlabcentral › answers › 472122-covariance-matrix-and-principal-components
Covariance matrix and principal components - MATLAB Answers - MATLAB Central
July 17, 2019 - Then the eigenvectors (W) don't look like the analytic eigenvectors from the analytic covariance matrix. However if I instead calculate cov of realization_mat', the transposed, then the eigenvectors (W2) look like the analytic ones. However, on the help (https://la.mathworks.com/help/matlab/ref/cov.html) it is stated that the rows of A should be observations and the columns, variables; therefore, eig(cov(realization_mat)) should offer good eigenvectors, no teig(cov(realization_mat)).
MathWorks
mathworks.com › matlabcentral › answers › 477339-covariance-between-the-estimated-parameters-from-curve-fitting-toolbox
covariance between the estimated parameters from curve fitting toolbox - MATLAB Answers - MATLAB Central
August 23, 2019 - Thank you. with MSE and Jacobian from output Optimization Toolbox I can calculate covariance matrix. ... https://www.mathworks.com/matlabcentral/answers/477339-covariance-between-the-estimated-parameters-from-curve-fitting-toolbox#comment_1452777
MathWorks
mathworks.com › phased array system toolbox › beamforming and direction of arrival estimation › beamforming
sensorcov - Sensor spatial covariance matrix - MATLAB
This MATLAB function returns the sensor spatial covariance matrix, xcov, for narrowband plane wave signals arriving at a sensor array.
MathWorks
mathworks.com › matlabcentral › answers › 1464934-how-to-obtain-the-3-x-3-symmetric-covariance-matrix-of-a-3x1-matrix
How to obtain the 3 × 3 symmetric covariance matrix of a 3x1 matrix? - MATLAB Answers - MATLAB Central
October 1, 2021 - So while the underlying process that generated the vector may have a well defined covariance matrix, you cannot compute it from one vector. You need more data. You cannot squeeze blood from a rock. Well, you might get blood if you try, but if you look at your hands, the blood came from your own fingers. Sorry. Sign in to comment. Sign in to answer this question. Find more on Matrix Indexing in Help Center and File Exchange ... Find the treasures in MATLAB Central and discover how the community can help you!
MathWorks
mathworks.com › matlabcentral › answers › 1610815-find-matrix-covariance-by-fitting-data-as-a-parabola
Find matrix covariance by fitting data as a parabola - MATLAB Answers - MATLAB Central
December 14, 2021 - In MATLAB, you can fit a parabola ... degree (2 for a parabola). You can also obtain the covariance matrix of the coefficients using the same function by requesting two output arguments....