MATLAB Answers

How to get correlation for multiple columns

132 views (last 30 days)
As Matlab newbie I'm trying to get correlation of the first column itself and all the others, but can't handle.
Error: You cannot subscript a table using linear indexing (one subscript) or multidimensional indexing (three or more subscripts). Use a row subscript and a variable subscript.
My code:
X = table(Tmin.P1,Tmin.P2,Tmin.H1,Tmin.H2,Tmin.Z1,Tmin.Z2,Tmin.S1)
for i=1, k=0
i=i+1;
k=k+1;
B(k,:)=corr(X(:,1),X(:,i));
end

  0 Comments

Sign in to comment.

Accepted Answer

jonas
jonas on 11 Nov 2018
Edited: jonas on 11 Nov 2018
Why not just calculate the entire correlation matrix, and then extract the first row or col?
cm = corr(X)
c1n = cm(:,1)
If X is a table, then you need to write something like
cm = corr(X{:,:})
or
cm = corr(X.Variables)

  0 Comments

Sign in to comment.

More Answers (1)

Csongor Báthory
Csongor Báthory on 13 Nov 2018
Thank you!
More easier that I thinked. Get to know the basics :)

  0 Comments

Sign in to comment.

Sign in to answer this question.