How to do correlation from data with series

1 view (last 30 days)
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 Comment
Adam Danz
Adam Danz on 18 Jan 2021
Edited: Adam Danz on 20 Jan 2021
Note that if you're using string arrays, use square brackets.
p=["1","1","1","1","1","2","2","2","2","2"];

Sign in to comment.

Accepted Answer

Adam Danz
Adam Danz on 14 Jan 2021
Edited: Adam Danz on 15 Jan 2021
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}

More Answers (0)

Community Treasure Hunt

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

Start Hunting!