How to plot time with correlation of two matrix?

2 visualizaciones (últimos 30 días)
Madan Kumar
Madan Kumar el 3 de Jun. de 2022
Comentada: Mathieu NOE el 3 de Jun. de 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.

Respuesta aceptada

Mathieu NOE
Mathieu NOE el 3 de Jun. de 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)

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by