How to get correlation for multiple columns

조회 수: 16 (최근 30일)
Csongor Báthory
Csongor Báthory 2018년 11월 10일
답변: Csongor Báthory 2018년 11월 13일
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

채택된 답변

jonas
jonas 2018년 11월 11일
편집: jonas 2018년 11월 11일
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)

추가 답변 (1개)

Csongor Báthory
Csongor Báthory 2018년 11월 13일
Thank you!
More easier that I thinked. Get to know the basics :)

카테고리

Help CenterFile Exchange에서 Correlation and Convolution에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by