Correlation between multiple columns of table

Hi guys!
I have a table (see attached) for which I want to calculate corrcoef ([r p]) between multiple columns. Eg. between column 2 and column 6, column 2 and column 7, then column 3 and column 6, column 3 and column 7. The last combination would be column 5 and column 12.
Is there a way to do it a with a loop (or any other way, as a matter of fact) and automatically store the values in a new table so that I don't mix them up?
Thanks in advance!
I'm on Matlab 2019a.

回答(1 个)

iwant = zeros(2,2,[]) ;
count = 0 ;
for r = 2:3
for p = 6:7
count = count+1 ;
iwant(:,:,count) = corrcoef(data(:,r),data(:,p)) ;
end
end
iwant(:,:,count+1) = corrcoef(data(:,5),data(:,12)) ;

3 个评论

Thank you for your answer.
I tried your way but I get
Error using corrcoef (line 114)
Subscripting a table using linear indexing (one subscript) or multidimensional indexing (three or more subscripts) is
not supported. Use a row subscript and a variable subscript.
How did you read the file? What I have shown in the code is for a matrix. If you have a table, the indexing differs. You need to use data.(i) etc.
Actually the attached file is a double that I have produced earlier in the code, it's the outerjoin between two tables.

请先登录,再进行评论。

类别

帮助中心File Exchange 中查找有关 Matrices and Arrays 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by