Why I can't run the corrcoef for matrix

3 ビュー (過去 30 日間)
Karina Gutierrez
Karina Gutierrez 2016 年 11 月 28 日
コメント済み: Karina Gutierrez 2016 年 11 月 28 日
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 件のコメント
Karina Gutierrez
Karina Gutierrez 2016 年 11 月 28 日
編集済み: Karina Gutierrez 2016 年 11 月 28 日
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

サインインしてコメントする。

採用された回答

Steven Lord
Steven Lord 2016 年 11 月 28 日
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 件のコメント
Karina Gutierrez
Karina Gutierrez 2016 年 11 月 28 日
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

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCorrelation and Convolution についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by