# Corrcoef of two variables of unequal lengths

9 visualizaciones (últimos 30 días)
Ben Yang el 12 de Dic. de 2012
Editada: dpb el 29 de Dic. de 2019
Hi all! I'm new to MATLAB and I seem to be stuck with an issue that may be quite basic.
I have two variables that I want to apply the corrcoef function on. These variables, however, have different lengths, such that when I use the corrcoef function, I get:
??? Error using ==> corrcoef at 73 The lengths of X and Y must match.
Initially, length(Variable A) = 62 after removing the NaN's it became 60
Variable B is actually a zscored data of another variable, so the NaN's have already been removed before z-scoring. The length of Variable B is at 61.
Is it possible for me to get the corrcoef? If so, how?
It's strange that I've tried Googling for a solution but can't find anything that helps.
##### 0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

### Respuesta aceptada

Roger Stafford el 12 de Dic. de 2012
Editada: dpb el 29 de Dic. de 2019
Mathworks states in their description of corrcoef,
"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."
To be meaningful in such correlation calculations, variable values in your two variable vectors within the same row should be matched observations, that is, values that were made in the same observation. Therefore you shouldn't eliminate a NaN in one variable without also eliminating the corresponding entry in the other variable even if it isn't a NaN. As a corollary to this the two variable vectors must therefore remain of the same length.
If you don't maintain this correspondence between matching observations, you will obtain nonsensical results.
Roger Stafford
##### 0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

### Categorías

Más información sobre Particle & Nuclear Physics en Help Center y File Exchange.

### Community Treasure Hunt

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

Start Hunting!

Translated by