# How to plot time with correlation of two matrix?

2 views (last 30 days)
Madan Kumar on 3 Jun 2022
Commented: Mathieu NOE on 3 Jun 2022
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 on 3 Jun 2022
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 CommentsShowHide 1 older comment
Mathieu NOE on 3 Jun 2022
My pleasure !