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 Center および File ExchangeCorrelation and Convolution についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by