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

Learn moreOpportunities for recent engineering grads.

Apply Today**New to MATLAB?**

Asked by Aditya
on 5 Dec 2012

Hi,

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.

*No products are associated with this question.*

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);

## 1 Comment

## Lalit Patil (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/55734#comment_115412

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..

or

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