Use of Correlation function( corr)

54 views (last 30 days)
Abhivyakti
Abhivyakti on 21 Aug 2012
I am new to MATLAB.
I need to test correlation function on a data set in the form of a table(1x9757). When i input this into the correlation function, a new matrix if formes with size 9757x9757. But all the values in it are 'NaN' and in the workspace (where the size and minimum and maximum values of variables is mentioned), in the column of minimum and maximum value a message comes that says, 'Too many elements'.
Could anyone please help me with this. I am stuck on this from a very long time.
Thanks!
  1 Comment
José-Luis
José-Luis on 21 Aug 2012
Edited: José-Luis on 21 Aug 2012
Strange. If your matrix is 1 * 9757 , then there is no correlation to be calculated and the result of corr() should be one. Some data would help to understand the problem.
Cheers!

Sign in to comment.

Answers (1)

Star Strider
Star Strider on 21 Aug 2012
Edited: Star Strider on 21 Aug 2012
I am not sure what you want to do. The reason you are getting a large matrix of NaN values is that you are correlating a vector against itself with a function that calculates the linear correlation of 2 or more vectors. To use corr, you have to have at least a [N x 2] or [2 x N] matrix, or at least 2 vectors of the same size.
If you want to get the autocorrelation of the vector with itself, use the xcorr function in the Signal Processing Toolbox.
  2 Comments
Abhivyakti
Abhivyakti on 21 Aug 2012
That is helpful, you are right, im a little confused of what i really wish to calculate. Anyhow, could you please tell me where 'corrcoef' is used.
Star Strider
Star Strider on 21 Aug 2012
Edited: Star Strider on 21 Aug 2012
The problem is not with you but with the way different techniques have been named over the years. There are many different functions and measures with quite similar names and interpretations. You have already discovered autocorrelation and cross-correlation.
The correlation coefficient is one of a number of measures used to characterize the linear relationship between two (or more) sets of data. I refer you to a good statistics textbook for a discussion of the various measures and statistics and how they are applied.
From the respective documentation for the functions that calculate the correlation coefficient:
RHO = corr(X) returns a p-by-p matrix containing the pairwise linear correlation coefficient between each pair of columns in the n-by-p matrix X.
and:
R = corrcoef(X) returns a matrix R of correlation coefficients calculated from an input matrix X whose rows are observations and whose columns are variables.
The only way to determine the function you need of all those with some relationship to ‘correlation’ is to explore them and experiment with them to find out which one most closely matches your data and what you want to know about it.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!