Reputation: 27
I have two sets of data. Each of them is a matrix and they have two columns, first column represents index x and second represents y. I want to see how similar are the curves of these datasets. In other words I need to have the correlation of these two curves represented by two matrices. Thanks for help.
Upvotes: 0
Views: 2425
Reputation: 13945
You might be looking for the corr2 function which calculates the correlation coefficient for each corresponding values in your matrices:
CorrMatrix = corr2(A,B)
plot(x,CorrMatrix);
Is that what you meant? If not please don't hesitate to ask for more details.
For matrices of unequal size I think you only have these options:
If you have the Signal Processing Toolbox you can use the cross-correlation function xcorr2, otherwise you can do the following:
1)either you calculate the correlation of you data where you use a part of the larger matrix so that the number of elements are similar: (the values I use are really dummy values sorry.)
clear
clc
% Create dummy matrices of unequal sizes
x =1:10;
x2 = 1:6;
A(:,1) = x;
A(:,2) = sin(x);
B(:,1) = x2;
B(:,2) = cos(x2);
A,B
C = corr2(A(1:6,:),B)
A =
1.0000 0.8415
2.0000 0.9093
3.0000 0.1411
4.0000 -0.7568
5.0000 -0.9589
6.0000 -0.2794
7.0000 0.6570
8.0000 0.9894
9.0000 0.4121
10.0000 -0.5440
B =
1.0000 0.5403
2.0000 -0.4161
3.0000 -0.9900
4.0000 -0.6536
5.0000 0.2837
6.0000 0.9602
C =
0.9463
or 2)
After some googling I saw that a similar question was posted here, in which it said that you can play around with Fourier transforms to get the correlation:
Cross-correlation in matlab without using the inbuilt function?
Upvotes: 1