How to plot time with correlation of two matrix?

2 ビュー (過去 30 日間)
Madan Kumar
Madan Kumar 2022 年 6 月 3 日
コメント済み: Mathieu NOE 2022 年 6 月 3 日
Hi,
I have two matrices (each of 1000*50), here let's say A and B. The time resolution of both the martices are same (corresponds to the number of rows). I need to calculate the time variation of the correlation of A and B and plot it (i,e, plot(time, correlation)). My code is like below, let's say time is t=1:7 sec;
A=[1 2 3 4;4 6 5 7; 1 8 9 3; 1 2 3 4; 3 2 4 1; 4 3 2 1; 5 6 7 4];
B=[0 1 2 3;3 5 5 7; 2 9 9 3; 2 3 4 4; 5 66 7 2; 8 9 10 11; 15 26 17 14];
R=zeros(size(B,1),1);
for i=1:size(B,1)
R(i)=corrcoef(A(i,:),B(i,:),'alpha',0.05);
end
plot(time,R)
I need to calculate correlation between A(1,:) and B(1,:), then A(2,:) and B(2,:) and so on so that the time remain same (correlation at everytime) and I get correlation as same rows as the time. Can anyone help me. Thank you.

採用された回答

Mathieu NOE
Mathieu NOE 2022 年 6 月 3 日
hello
here you are :
A=[1 2 3 4;4 6 5 7; 1 8 9 3; 1 2 3 4; 3 2 4 1; 4 3 2 1; 5 6 7 4];
B=[0 1 2 3;3 5 5 7; 2 9 9 3; 2 3 4 4; 5 66 7 2; 8 9 10 11; 15 26 17 14];
R=zeros(size(B,1),1);
for i=1:size(B,1)
M = corrcoef(A(i,:),B(i,:),'alpha',0.05);
R(i)= M(2,1); % we pick the non diagonal term (symmetrical) M(2,1) = M(1,2)
time(i) = i;
end
plot(time,R)
  2 件のコメント
Madan Kumar
Madan Kumar 2022 年 6 月 3 日
Thank you so much.
Mathieu NOE
Mathieu NOE 2022 年 6 月 3 日
My pleasure !

サインインしてコメントする。

その他の回答 (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