0

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.

1 Answers1

1

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?

Community
  • 1
  • 1
Benoit_11
  • 13,905
  • 2
  • 24
  • 35
  • These two matrices I work with have different row numbers. Can I use correlation function with different row numbers? – user3460203 Jul 04 '14 at 20:01
  • Let me explain myself a little bit more: In the first of column I have the time information and in the second column I have certain values for that time instant. The ending time is the same however one of the matrices have a lot more information in between the time period so that one has more rows. It is like this: A = [ 1 2 ; 2.3 5.6 ] B = [ 1 1.2 1.6 2; 2.4 2.6 4.8 ]. I want to see the similarity of the curves which are the results of these kind of matrices. – user3460203 Jul 04 '14 at 21:23