How to do correlation from data with series

조회 수: 2 (최근 30일)
Filip Wylegala
Filip Wylegala 2021년 1월 14일
편집: Adam Danz 2021년 1월 20일
Hi i have to make corelation to check the dependance of variable c from series 1 or 2. Can I split t vector into two one t1 and t2 make 2 seperet correlations of t1 to c1 and t2 to c2?
t=[21,22 ,323,43,231,53,23,12,53,12]
c=[23,12 ,223,333,21,63,24,23,763,14]
p={"1","1","1","1","1","2","2","2","2","2"}
  댓글 수: 1
Adam Danz
Adam Danz 2021년 1월 18일
편집: Adam Danz 2021년 1월 20일
Note that if you're using string arrays, use square brackets.
p=["1","1","1","1","1","2","2","2","2","2"];

댓글을 달려면 로그인하십시오.

채택된 답변

Adam Danz
Adam Danz 2021년 1월 14일
편집: Adam Danz 2021년 1월 15일
You can use xcorr and indexing.
t=[21,22 ,323,43,231,53,23,12,53,12];
c=[23,12 ,223,333,21,63,24,23,763,14];
p=["1","1","1","1","1","2","2","2","2","2"]; % <-- String array with square brackets
[groupID, groups] = findgroups(p)
groupID = 1×10
1 1 1 1 1 2 2 2 2 2
groups = 1×2 string array
"1" "2"
xcorr(c(groupID==1), t(groupID==1))
ans = 1×9
0.0531 0.0376 0.5946 0.9089 0.9195 1.1362 0.1879 0.0745 0.0044
xcorr(c(groupID==2), t(groupID==2))
ans = 1×9
0.0756 0.3627 0.2304 1.2112 4.4774 1.1699 1.8936 4.0761 0.0742
or use splitapply
splitapply(@(x1,x2){xcorr(x1,x2)}, c, t, groupID)
ans = 1x2 cell array
{1×9 double} {1×9 double}

추가 답변 (0개)

카테고리

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