Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
column by column correlation coefficient of two matrices

Subject: column by column correlation coefficient of two matrices

From: M

Date: 21 Mar, 2005 17:26:41

Message: 1 of 3

hi there,

i have two matrices,A and B.
each column of matrix A corresponds to a column of matrix B.
what i want is the correlation coefficient of the corresponding
columns.

i could do it like this:

for i=1:size(A,2)
   temp=corrcoef(A(:,i),B(:,i))
   C(i)=temp(1,2);
end

the problem is that i want to somehow remoe the for lopp as it is
very time consuming. and the size of my matrices are really huge!

can you think of any way that i can vectorize this solution?

thanks,
M

Subject: column by column correlation coefficient of two matrices

From: Nick

Date: 12 Dec, 2008 06:09:33

Message: 2 of 3

c = corr(a,b);

cc = diag(c);

Subject: column by column correlation coefficient of two matrices

From: Peter

Date: 3 Aug, 2012 17:54:44

Message: 3 of 3

a = detrend(A,'constant');
b = detrend(B,'constant');
C = sum(a.*b)./sqrt(sum(a.*a).*sum(b.*b));

On Monday, March 21, 2005 2:26:41 PM UTC-8, M wrote:
> hi there,
>
> i have two matrices,A and B.
> each column of matrix A corresponds to a column of matrix B.
> what i want is the correlation coefficient of the corresponding
> columns.
>
> i could do it like this:
>
> for i=1:size(A,2)
> temp=corrcoef(A(:,i),B(:,i))
> C(i)=temp(1,2);
> end
>
> the problem is that i want to somehow remoe the for lopp as it is
> very time consuming. and the size of my matrices are really huge!
>
> can you think of any way that i can vectorize this solution?
>
> thanks,
> M

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us