How to plot time with correlation of two matrix?

조회 수: 1 (최근 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)

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Correlation and Convolution에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by