Error in Cross correlation (crosscorr command) in MATLAB

I have a problem with a code. I have two kinds of data (lets call them a and b). These are cells, and in each cell I have double/numbers (see images attached). I would like to cross correlate , using a loop, data of a with data of b. I am using the following code:

for i=1:numel(a)
[c,lag]=crosscorr(a{i},b{i})
r = [0.65, 1];
ii = c >= r(1) & c <= r(2)

% this finds the index of he rows(2) that have x in between 
idx = find(abs(c) > r(1) & abs(c) <= r(2));
% number of intervals with positive check
numIdx{i} = sum(abs(c) > r(1) & abs(c) <= r(2))
Final{i}=(numIdx{i})'
n=Final'

 end

but I realise that the results are wrong, as I should have 100% correlation bacause of the similarity of the numbers.enter image description here

1 answer

  • answered 2021-02-24 11:31 user12750353

    crosscorr will compute the correlation between shifted versions of your data. This is useful to synchronize time series or to align versions of an image. You will have only one of the attempts that matches perfectly1, the rest may be uncorrelated. To measure correlation between aligned samples you can use corr