Why I can't run the corrcoef for matrix

17 visualizaciones (últimos 30 días)
Karina Gutierrez
Karina Gutierrez el 28 de Nov. de 2016
Comentada: Karina Gutierrez el 28 de Nov. de 2016
Hi All, I am trying to run corrcoef to obtain the matrix of correlation coefficients and p-values but keep getting an error. I am using:
R = corrcoef (tbl);
(tbl is a 1050x5 table)
And this is the error I get:
Undefined function 'sum' for input arguments of type 'table'.
Error in cov (line 154) xc = bsxfun(@minus,x,sum(x,1)/m); % Remove mean
Error in corrcoef>correl (line 206) r = cov(x);
Error in corrcoef (line 89) r = correl(x);
Could someone please advise me what am I doing wrong and how to run this analysis?
Thanks in advance, Karina
  1 comentario
Karina Gutierrez
Karina Gutierrez el 28 de Nov. de 2016
Editada: Karina Gutierrez el 28 de Nov. de 2016
Never mind, I just give it a second thought and realized that I had the input with the format of a table and not a matrix and this was creating the issue.
I created a matrix with the same data as the table and now it run just fine.
I guess I still don't understand the difference between a matrix and a table?
Cheers, Karina

Iniciar sesión para comentar.

Respuesta aceptada

Steven Lord
Steven Lord el 28 de Nov. de 2016
You can't compute the correlation coefficient of a table since a table could contain non-numeric data. Instead, you can compute the correlation coefficient of one or more variables in the table.
x = (1:10).';
y = x.^2;
t = table(x, y);
ycc = corrcoef(t.x, t.y)
If your variables can be concatenated into a matrix, you can pass the Variables from the table into corrcoef.
cc = corrcoef(t.Variables)
  1 comentario
Karina Gutierrez
Karina Gutierrez el 28 de Nov. de 2016
Thanks for your super fast response Steve, I concatenated the variables into a matrix and was able to run the correlation coefficient.
So just for clarification, is the main difference between a table and a matrix that tables can store non numerical values and matrices are only for numerical values? And if so, when doing any calculations is better to have matrices right?
Sorry, I am pretty new to Matlab and I still get easily confused.
Cheers,
Karina

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by