MATLAB Answers


How can I find a correlation between two matrices

Asked by Aditya
on 5 Dec 2012


I am trying to find a correlation between two matrices. I want to know how to make use of the command corrcoef(x,y). Or any other command would also be good.

I have following data - x - is a 35 by 1000 matrix, y- is a 13 by 1000 matrix. I want to find a sorted order of correlation between rows from x (i.e. 35) with each row in element in y (13 in my case) for all the 1000 columns.

So for example, it could be like for the 1st row in y would be correlated to say 10 rows in x and the rest could be uncorrelated. So, I wish to find that set and what is the exact descending order for each row in x with y.

I have tried using the command corrcoef(x,y), but it is not giving me what I am looking for. I have also tried few other commands like corr(x,y).

Thanks, Adi.

  1 Comment

Two ways..

First short your string of first matrix ,both rows and columns, like cropping in image. then short your string of second matrix, both rows and columns. So, both matrix sizes will be same..


second do zero padding in one of the matrix so size will be same of both matrices, then do correlation..

Log in to comment.

1 Answer

Answer by Andrei Bobrov
on 5 Dec 2012

one way:

out = corr( cell2mat(cellfun(@(x1)interp1(x1,linspace(1,size(x,1),size(y,1))),num2cell(x,1),'un',0)),y);


Log in to comment.

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today