# Correlation between multiple columns of table

8 views (last 30 days)
Daphne PARLIARI on 18 Jun 2021
Commented: Daphne PARLIARI on 18 Jun 2021
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?
I'm on Matlab 2019a.

KSSV on 18 Jun 2021
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 CommentsShow 1 older commentHide 1 older comment
KSSV on 18 Jun 2021
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.
Daphne PARLIARI on 18 Jun 2021
Actually the attached file is a double that I have produced earlier in the code, it's the outerjoin between two tables.